• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Same entity beans check ?

 
Ashley Bideau
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Identify the correct statements regarding the object identity of entity beans.



Select 1 correct option.
a A client can determine whether two entity beans are same by comparing their primary key using equals method.

b Equality of any two entity beans can be tested by comparing each individual field of their primary key.

c Equality of any two entity beans can be tested by using the isIdentical() method of EJBObject.


d If the primary keys of two beans are found to be equal using the isIdentical() method, then the beans are same.
 
Rajesh Chande
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ashley,

I would go for "c".

By the way, it would be good to write your opinion along with and also mention your doubt at the first go... no?

Regards,
Tiro.
 
Arun Natarajan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
c seems to be the best choice, but looks like options a and b are correct too.
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think D is also correct besides C assuming option D is talking about Entity Beans.
[ July 22, 2006: Message edited by: Ugender Rekulampally ]
 
usha mocherla
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I guess option a is correct.

If a client receives 2 entity references from the same Home, it can determine whether they refer to the same or different beans by comparing

1. Their primary keys using the equals() method.

2. by comparing their references on isIdentical() method. (always use this method to compare references)


Note: you should never use == operator or equals method to compare two object references.
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usha,
I am not sure whether option A is correct or not but see my assumptions to say A may be wrong:

if you have two entity beans at client side (since you are using equals to compare so this is not a remote method call and it compares only in local heap,not like isIdentical) with same primary keys I guess there is a possibility that other fields can be different eventhough the primary key values are same (assume, those Beans didnt get updated or container not yet involved to update the DB), is n't it?

I may be wrong but if any one writes a program to see what happens, can you guys post the result here?


Thanks,
Ugender
[ July 23, 2006: Message edited by: Ugender Rekulampally ]
 
Rajesh Chande
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have taken the following from the specification as-is:

- If two entity objects have the same home AND the same primary key, they are considered identical.
- A client can test whether two entity object references refer to the same entity object by using the isIdentical method. Alternatively, if a client obtains two entity object references from the same home, it can determine if they refer to the same entity by comparing their primary keys using the equals method.
-The result of comparing two object references using the Java programming language Object.equals(Object obj) method is unspecified. Therefore, a client should always use the isIdentical method to determine if two entity object references refer to the same entity object.

now considering all the above since the question says - select only 1 option, "c" would be my BEST bet, and if given to select 2nd option, that would be "a".

What say?
 
Ugender Rekulampally
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tiro,
Thanks for your research and info.
I am still not clear the explanation that we have here to pick option A. Yes, you always can use the equals method to test but the result is unclear since it doesn't contact the remote heap to make sure the values are same even though primary keys are same..

Think about in programming way, if you try to update something in a bean other than a primary key at your local heap and compare another bean with the same primary and you just got it from Server, so in this case, two beans are from same home, same primary key but still some of the fields are different and I think this should return false since the values are different.

And I believe option D is right in case of Entity Beans. Since we are using isIdentical() so it is a remote method and it will make sure that the two instances have the exact value for the same primary key values.


I still think Options C and D are correct..

I know option A is very tempting but you are using equals method which does the trick...if some one can write a program to see it ...please post the results here..

Thanks,
Ugender
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"I am still not clear the explanation that we have here to pick option A. Yes, you always can use the equals method to test but the result is unclear since it doesn't contact the remote heap to make sure the values are same even though primary keys are same.."

You can always use getPrimaryKey() method on component interface to get the primary key in the client code. Then you can compare the primary keys using equals method.

And option D can never be correct as isIdentical is used to compare EJBObjects only.
 
paresh vernekar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Ugender seems to be having a valid point in terms of programming.
However, I guess we should be looking at what we are trying to achieve when we are trying to see if remote entities are equal.Although there will be multiple remote clients having references to an entity at a given time, there is only one entity in the datasource.If it has been established that the primary key is equal that means the references are equal.The object state at any given point of time which is available with multiple clients doesn't matter.

So I think A,B and C are correct options.A and B are essentially the same although the way comparision is done is different

Regards,
Paresh Vernekar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic