• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question aboute stateless session bean equals

 
Fu Dong Jia
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Goutham Pallipati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic