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.
posted 12 years ago
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?
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".
posted 12 years ago
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..
"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.
SCJP 1.4 : 91%
SCWCD 1.4 : 95%
SCBCD 1.3 : 95%
SCJP 6 Upgrade : 95%
Next SCBCD 1.5
Man is not finished when he is defeated. He is finished when he quits.
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