• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Derived attribute problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Derived attribute problem


  • Subject: Re: Derived attribute problem
  • From: Ângelo Andrade Cirino <email@hidden>
  • Date: Sun, 23 Mar 2014 14:23:00 -0300

Hi Aaron,

It is a mystery to me. I deleted the entity, saved the model, quit EOModeler, relaunched EOModeler, recreated the entity as a ERXGenericObject, added the derived attribute and it worked finely.

Then I changed the entity to a custom class and the derived attribute continued to work. So I added a second derived attribute to my custom class and it worked too.

What a pity that I am having this intermittent problems, the productivity is way lower than it should be.

Thanx for your help,

Angelo


2014-03-23 14:11 GMT-03:00 Aaron Rosenzweig <email@hidden>:
Hi Angelo,

There is something you and I are both missing. 

1) There should be nothing magic about GenericRecord versus CustomObject. All of my EOModels have CustomObjects for the reasons you noted (you want to add helper methods, etc.). They also have both derived attributes but more often regular attributes that use read / write format. I’ve never received the error you encountered. 

2) Maybe you are using a special MySQLPlugin that has some issue. I tried searching for bits and pieces of the error message that was generated for you but I can’t find it in my code base. 

3) It looks like your ReadFormat test was on the cusp of working. An “IllegalStateException” is a java error meaning it never got to the point of talking to the Database before throwing up its hands. A “JDBCAdaptorException” means that the java knew what you were asking so went ahead to query the DB but then had a problem. Double check that you had the correct prototype (varchar) for the attribute in your EOModel. Double check that the raw SQL would work. Turn on “EOAdaptor Debug” so you can see the generated SQL and verify by hand that it makes sense. 

log4j.logger.er.transaction.adaptor.EOAdaptorDebugEnabled=DEBUG

Sorry you’re having trouble with this.
Aaron Rosenzweig / Chat 'n Bike
e:  email@hidden  t:  (301) 956-2319
Chat 'n Bike Chat 'n Bike

On Mar 23, 2014, at 11:58 AM, Ângelo Andrade Cirino <email@hidden> wrote:

Hi Aaron,

Thank you for your prompt answer. Unfortunately none of the suggestions worked.

1) I can't find any combination of double or single apostrophe that will work. A similar MySQL SELECT statement is as simple as this

select Party.id as partyID, (case status
when 0 then 'Active'
when 1 then 'Inactive'
    end) as fullStatus from Party;

Even this simple derived attribute that returns a constant won't work (from the plist entity file):

{
columnName = fullStatus; 
definition = "'Full Status'"; 
name = fullStatus; 
prototypeName = varchar16; 
}, 

with the following error:

IllegalStateException: sqlStringForAttribute: attempt to generate SQL for attribute 'fullStatus' on entity 'Party' with undefined column name. You must define a column name for this attribute before attempting a database operation.

2) The read format option didn't work either since the attribute is an integer number and the return value is a string. I attempted this format:

if(%P,'Active','Inactive')

and it resulted in this error:

JDBCAdaptorException: Invalid value for getInt() - 'Inactive'

However, this works just fine as a read format:

if(%P,2*%P,5*%P)

But I am stubborn and think that a derived attribute is a desirable attribute. I would like to use it for more complex operations, for example involving concatenation of strings in related entities.

Anyway, trying to figure out what is happening, it occurred to me that my Party entity is a custom class, so I tried a non-custom class with a simple entity to see if the derived attribute would work. And it worked. My simple tentative entity is this:

{
    attributes = (
        {columnName = code; name = code; prototypeName = intNumber; }, 
        {
            columnName = fullStatus; 
            definition = "case code when 0 then 'Active' when 1 then 'Inactive' end"; 
            isReadOnly = Y; 
            name = fullStatus; 
            prototypeName = varchar16; 
            userInfo = {"_EntityModeler" = {generateSource = NO; }; }; 
        }, 
        {allowsNull = N; name = id; prototypeName = id; }
    ); 
    attributesUsedForLocking = (code, id); 
    className = "er.extensions.eof.ERXGenericRecord"; 
    classProperties = (code, fullStatus); 
    externalName = Status; 
    fetchSpecificationDictionary = {}; 
    name = Status; 
    primaryKeyAttributes = (id); 
}

But this isn't a solution for me, since my entity will have a lot of business logic that demands a custom class. Perhaps I should set my Party entity as a ERXGenericRecord and then subclass it to implement the business logic.

The question is, why does EO expect a column for a derived attribute for a custom class and not for a ERXGenericRecord?

By the way, the original Apple EOModeler User Guide doesn't state that a derived attribute will not work for a custom class nor does the documentation states that a derived attribute should be modeled for a generic record.

Angelo

2014-03-23 1:01 GMT-03:00 Aaron Rosenzweig <email@hidden>:
Hi Angelo,

Couple things to try:

1) Remove the single apostrophes surrounding “status” and try again. It is possible that it isn’t parsing properly… don’t column names need to have “double apostrophes” ??? Perhaps MySQL is lax about that but still… Either use no apostrophe or use a “double apostrophe” meaning a single character the shift-apostrophe key. If it is a single apostrophe that is a String in SQL. 

2) Try a different way. Remove all the code you have in the derived part and make this a normal EOAttribute. Put “STATUS” in there by itself. Now go to the “advanced” tab and type what you want in the “Read Format” and check the “read only” box. In the read format you want to use %P for your columnName so you’ll want something like this:

case %P when 0 then 'Active' when 1 then 'Inactive’ end

Honestly, I almost always use the #2 way and never the “derived” way because it is more flexible. I like the idea that I define the column in one box and in another I write something complex but refer to it with %P. 

Try it out and report back.
Aaron Rosenzweig / Chat 'n Bike
e:  email@hidden  t:  (301) 956-2319







--
Ângelo Andrade Cirino
email@hidden
31-3494-8642
31-9303-0695
MSN email@hidden
Skype aacirino
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: Aaron Rosenzweig <email@hidden>)
 >Re: Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: Aaron Rosenzweig <email@hidden>)

  • Prev by Date: Re: Derived attribute problem
  • Next by Date: Re: Derived attribute problem
  • Previous by thread: Re: Derived attribute problem
  • Next by thread: Re: Derived attribute problem
  • Index(es):
    • Date
    • Thread