• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt : stateless bean dependency injection

 
B Misra
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across a note where it says obtaining two instances of a stateless bean via dependency injection will always be equal.

I tested it and it is true.

@EJB MySLBeanLocal mySLBean1;
@EJB MySLBeanLocal mySLBean2;

mySLBean1.equals(mySLBean2) always returns true.

But I am not sure what is the reason behind it? Isn't that while invoking stateless bean like that it is always upto the container to return which object from pool?

Any clarification will be really helpful.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the EJB specification, the container always maintains equal instances of the Stateless Session beans in its pool. There is no state associated with Stateless session beans. Can you now make it out?
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In the ejb 3.0 specification on page 47 (3.4.5.2 Stateless Session Beans) you can find
The equals method always returns true when used to compare references to the same business interface type of the same session bean. Session bean references to either different business interface types or different session beans will not be equal.


I hope that this helps, in the same document - somewhere upper - is they describe the equals for statefull.

Regards
Mihai
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic