| Author |
A question aboute stateless session bean equals
|
Fu Dong Jia
Ranch Hand
Joined: May 23, 2007
Posts: 131
|
|
Give the following clientside code:
10.@EJB Foo f1; 11.@EJB Foo f2; //more code here 20.boolean test1=f1.equals(f1); 21.boolean test2=f1.equals(f2); ...
If Foo is stateless,test1 is true(of course). I think test2 is false,because a method equals() have been invoked on f1,so container have been offered a special Foo instance to f1,so f1 is not equals to f2.But the answer for test2 is true. beg for help!
|
who dare win!<br />SCJP5(94%)|SCWCD5(86%)|SCBCD(100%)|SCEA in progress
|
 |
Ralph Jaus
Ranch Hand
Joined: Apr 27, 2008
Posts: 342
|
|
See core spec 3.4.5.2 (there is also a similar example like yours):
All business object references of the same interface type for the same stateless session bean have the same object identity, which is assigned by the container.
Remember from SCJP that equals() only checks that two objects are meaningfully equivalent.
|
SCJP 5 (98%) - SCBCD 5 (98%)
|
 |
Goutham Pallipati
Greenhorn
Joined: Aug 13, 2008
Posts: 20
|
|
Hi, In your case your are not getting the reference of the Bean where as the Reference of the Remote Object (Stub Class) which can be same in case of stateless bean. you do a lookup to the given bean and the server returns a reference in the form of RemoteObject Stub class implementation of your Remote interface. So when you call the equals method you are calling it on the Local Stub which extends LocalWrapperClass specific to container which might equate the actual bean to which the stub is pointing to. So if your lookup returns the remote reference to the same SessionBean in the memory then the equals might pass. No clear on the entire complex concepts but what I can say is if you lookup returns the references to same object in the Object Pool then the equality would pass.
|
 |
Ralph Jaus
Ranch Hand
Joined: Apr 27, 2008
Posts: 342
|
|
Goutham Pallipati wrote
So if your lookup returns the remote reference to the same SessionBean in the memory then the equals might pass. No clear on the entire complex concepts but what I can say is if you lookup returns the references to same object in the Object Pool then the equality would pass.
The result of equals() in the present context doesn't depend on the refernced pool objects at all! It only depends on the class of the business interface and the bean class. [ December 17, 2008: Message edited by: Ralph Jaus ]
|
 |
 |
|
|
subject: A question aboute stateless session bean equals
|
|
|