• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

really tricky question

 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..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 ]
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow ! Philippe,
you put response while I have written mine...
you're really fast, dude !
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you don't know *when* I started writing !
[ December 29, 2003: Message edited by: Philippe Maquet ]
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Asher, but I mentioned the "same home" requirement in my first reply.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"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 Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
different home but same JNDI name?

Is it even possible ?
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ! )
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Reply
  • Bookmark Topic Watch Topic
  • New Topic