After EJB Home getting create( ) call from client ( for Stateful Session Bean ), i) who is creating bean instance and EJB Object i.e) container or EJB Home ii) which is first created? iii) how these two are associated
Everything is explained in section 7.6 of the EJB 2.0 spec
A session bean instance�s life starts when a client invokes a create<METHOD> method on the session bean�s home interface. This causes the container to invoke newInstance on the session bean class to create a new session bean instance. Next, the container calls setSessionContext and ejbCreate<METHOD> on the instance and returns the session object reference to the client. The instance is now in the method ready state.
This means that the container first creates the session bean instance and then the session object and that the association between both is kept somewhere in the container.
Refer to the Object Interaction Diagram given in HFEJB in chapter 4. The order will be clear :
1. Client calls home.create(). The create method is called on the home object 2. EJBObject instance is created 3. SessionContext instance is created 4. Bean instance is created (Bean constructor runs) 5. setSessionContext() runs 6. ejbCreate() runs 7. EJBObject stub is returned to the client.
Expect a question on this in the exam . You need to memorize the exact order.
posted 14 years ago
Who creates the bean instance and the EJBObject? The container or the Home object?
What's the difference between the 2? Not much. The container writes the home object code and instantiates it. So whether the home object has the code to create the bean and the EJBObject or the container creates these outside of the home object's code, it does not matter. It's also container dependent and varies from vendor to vendor. In any case, it's the container's magic. How it implements the magic - through the home object or outside of it and how it associates the bean and EJBObject- you are not supposed to worry or know