Why we can use the SessionContext to get a reference to the EJB Object in the ejbCreate() of stateless session bean? When the Container invokes ejbCreate(), there are no client yet! The EJB object has not been linked to the bean. How could we access the EJB object?
there are no client yet! The EJB object has not been linked to the bean. How could we access the EJB object?
I think you have misunderstood, the ejbCreate() method is a container callback and container call this method when it receives a call on corresponding create() method in home object, means that some client invokes home.create() method. So before calling ejbCreate() container creates the EJB Object for current instance, that is why EJB object is available in this method.
By the time the ejbCreate() method is called, the setSessionContext() method has already been executed, and hence the session context has already been assigned to the bean and the EJBObject for this instance has been created. The container creates an instance, invokes the setSessionContext() method on it to give it a context, and then calls the ejbCreateMethod().
This is why we could access EJBObject in ejbCreate() of stateless session bean.
------- SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
Steven Gao Song
posted 11 years ago
No, I cannot understand yet.
Please refer to Page227 HFEJB. When the client calls the create() on the Home object, EJB Object is created. It has nothing to do with the ejbCreate() method! Only when the clients invoke the business methods, the EJB Object is linked with the bean instance.
The container creates the stateless session bean instance without creating the EJB Object. So, I still think that in ejbCreate() method, it is impossible to get the reference to bean's EJB object.