File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateless Session Bean setSessionContext operations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateless Session Bean setSessionContext operations" Watch "Stateless Session Bean setSessionContext operations" New topic

Stateless Session Bean setSessionContext operations

Suresh Ramamurthy

Joined: Aug 18, 2004
Posts: 7
Hi ,
I was going through the Stateless Session Bean OID Diagrams and operations allowed in the Stateless Session Methods.
In setSessionContext, we do have access to getEJBHome and getEJBLocalHome methods.
I am pretty much confused on why/how it was allowed to have access to these methods when the Session objects are pooled.
Keerthi P
Ranch Hand

Joined: Aug 19, 2003
Posts: 203
Yes. Session objects are pooled. But before they are put into the pool, according to the spec, the container must ensure that
1. EJB[Local]Home object is created for the family of session objects
2. setSessionContext() is called for the session bean instances so that the bean instances can access their context and EJB[Local]Objects.

Cheers.<br />Keerthi<br />(SCJP, SCWCD, SCBCD)
Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106
It's basically about who is accessible and who is not. As you know, a Stateless Session bean's creation is not linked to client calls in any way. The container creates the Stateless Session bean whenever it sees fit. When it does this, there will be no EJB Object, since there is no client yet. But there has to be a home already existing for this session bean gets created in the first place. Consequently, setSessionContext() allows you to get a reference to your home object.

Though the Stateless Session objects are pooled, it does not mean that they are de-linked from their home. They still are within the domain of and within the control of the Home that created them.

Regards,<br />Subhash Bhushan.
I agree. Here's the link:
subject: Stateless Session Bean setSessionContext operations
jQuery in Action, 3rd edition