Forums Register Login

really tricky question

+Pie Number of slices to send: Send
..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 ]
+Pie Number of slices to send: Send
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.


Regards,
Phil.
+Pie Number of slices to send: Send
if

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
+Pie Number of slices to send: Send
wow ! Philippe,
you put response while I have written mine...
you're really fast, dude !
+Pie Number of slices to send: Send
But you don't know *when* I started writing !
[ December 29, 2003: Message edited by: Philippe Maquet ]
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Hi Asher,

am i wrong?


I think so. We were talking of comparing two primary keys using equals(), which is legal and correct, not the beans themselves.
Regards,
Phil.
+Pie Number of slices to send: Send
right, but! the question is:


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 ?
+Pie Number of slices to send: Send
OK Asher, but I mentioned the "same home" requirement in my first reply.
+Pie Number of slices to send: Send
fine, i've seen that too. but, you still wrote "the answer is true". and i think, the answer is "false". exactly because of the home reason
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 


"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/
+Pie Number of slices to send: Send
 

different home but same JNDI name?


Is it even possible ?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

By the way, looks like there is a separate forum for mock exam errata here. Not sure how many people actually use it.


Right, but with a little 10 threads in two months, I don't think it's the right place to get an answer...
+Pie Number of slices to send: Send
phil,
the mocks errata forum idea is cool, but i'm afraid i won't be able to participate right now.... i'm just at chapter 3 ! )
+Pie Number of slices to send: Send
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.
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
https://gardener-gift.com


reply
reply
This thread has been viewed 738 times.
Similar Threads
how many EJBObjects
findByPrimary with different PK's is returning equals Entity Beans
How to model entity bean out of this?
some more HF final mock ques
Equality test for entity bean
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:58:33.