..at least to me, it's really tricky... A client can determine whether two entity beans are same by comparing their primary key using equals method. true or false? answer is false. -------------------------- well, i put the answer here, as someone said below that two entity beans are same if they are form the same home and have the same PK. So in the question it does NOT mention about whether they are from the same home, so it's false. Think about you have a Dog abcd, and you have a Cat abcd, though they have the same name(PK) "abcd" but they are not the same, obviously. So in essence, you can still compare PK as well as the home to determine whether two entity beans are same but why bother, just use isIdentical. [ December 29, 2003: Message edited by: Yi Meng ]
Hi Yi, Two entity beans are said identical (isIdentical() returns true) if they belong to the same home *and* have an equal primary key. So answer is true. If e1 and e2 are two component interfaces of entity beans from the same home, the beans are identical if e1.getPrimaryKey().equals(e2.getPrimaryKey()). FYI, about the primary key class (section 10.6.13 of the specs, p. 197), it's stated that :
The class must provide suitable implementation of the hashCode() and equals(Object other) methods to simplify the management of the primary keys by the Container.
this means that 2 entity beans with these PKs are the same (in fact, they points to the same entity - something in DB persistent storage), ONLY when these 2 beans are abtained from the same home interface (when they are of the same type). If question does not say whether these 2 entity beans are of the same type, the question is ambigous, nothing can be said for sure. To conclude : client *CAN* determine if 2 beans are equal when they are of the same type. Oh, almost forgot: hope, PK class propoerly overrides equals() too
actually, i think the answer should be FALSE... entity beans are remote objects. so, there is isIdentical() method for the comparison. you can't compare two remote objects using equals() method of java.lang.Object ... equals doesn't checks if both of the beans were gotten through the same EJBHome .. am i wrong?
posted December 29, 2003 03:55 AM -------------------------------------------------------------------------------- A client can determine whether two entity beans are same by comparing their primary key using equals method. true or false?
let's say the client has two entity beans. you can get their primary keys. if those keys are equal, it still doesn't say the beans are SAME. are you sure you've got them through the same home ?
Hi Asher, OK, you're right. I didn't read the first post as a mock question so I just focused on the correctness (or not) of comparing two primary keys using equals(). BTW, among the 4 mistakes (IMO) that I found out a few weeks ago in the final HF EJB mock exam (but I am still waiting for a confirmation from Kathy), there is one which closely relates to the subject of this thread :
Q 57 (p676) : C is mentioned as "true" : "If two entity object references are compared using the isIdentical() method, the container will return true if the two entity objects have the same primary key". The conditions are same primary key *AND* same home, so it should be "false".
Unfortunately, it's difficult to discuss here about final mock exam questions because it would influence other people's test score. It's probably better that Kathy and/or Bert mention mock exam mistakes in their errata, without any discussion here. Best, Phil.
phil, off-topic stuff.. what do you mean the "final hf ejb mock version". i'm reading the book right now. does the mock in the end of it is not final? do you know where can i find the book's errata site, including the mock's errors? thanks in advance
Hi Asher, Well the "final" mock exam is the one at the end of the book . You can find Head First EJB's errata here, but there is nothing yet about the final mock exam. Now I am thinking of starting a thread here for discussions about the final HF mock exam, but starting with a special warning like "PLEASE DON'T READ BEFORE TRYING THE MOCK EXAM BY YOURSELF !" What do you think ? Best, Phil.
"If two entity object references are compared using the isIdentical() method, the container will return true if the two entity objects have the same primary key". The conditions are same primary key *AND* same home, so it should be "false".
A bit curious........ What happens if the conditions are same primary key, different home but same JNDI name? Some errors can be viewed/submitted at the OReilly site. http://www.oreilly.com/catalog/hfjejb/errata/
Philippe, You are right. You caught me off guard mate!.... As long as the JNDI name is the same, it is always the same home object that is used. The local object variable that refers to this home object can be different, But there is one and only one home object for each bean type, atleast conceptually. Thanks for pointing it out! By the way, looks like there is a separate forum for mock exam errata here. Not sure how many people actually use it.
Hi Asher, If you're at chapter 3, it's too early for you, definitely ! But as you find the principle OK, I'll do it - probably tonight - with the warning I mentioned above. It should be enough to avoid disturbing those people who didn't try the mock exam yet. Thanks, Phil.
Post by:autobot
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
a bit of art, as a gift, the permaculture playing cards