Life Cycle of an Entity Bean

Figure 8.5 shows a simplified state diagram of an entity bean instance.

Figure 8.5. Simplified life cycle of an entity bean instance.


The following paragraphs describe the life cycle of an entity bean instance.

Initially, the bean instance does not exist.

Your bean instance's life cycle starts when the container creates the instance using Class.newInstance() and then calls the setEntityContext method. Now the instance enters a pool of available instances. An instance in the pooled state is not associated with any particular entity object identity. All instances in the pooled state are identical. While the instance is in the pooled state, the EJB container may use the instance to execute any of the entity bean's finder methods or home methods.

Your bean instance moves from the pooled state to the ready state when the container selects that instance to service a client call to an entity object. There are two paths from the pooled stage to the ready stage. On the first path, the client invokes the create method, causing the EJB container to call the ejbCreate and ejbPostCreate methods. On the second path, the EJB container invokes the ejbActivate method.

While in the ready state, the instance is associated with a specific entity object identity. The container calls business methods on the instance, based on the client call. The EJB container also can synchronize the state of the instance with the database using methods ejbLoad and ejbStore.

Eventually, the EJB container will transition the instance to the pooled state. This happens when the client calls the remove method, which causes the EJB container to call the ejbRemove method. Second, the EJB container might call the ejbPassivate method.

At the end of the instance's life cycle, the EJB container removes the instance from the pool and invokes the unsetEntityContext method.

Note

In bean-managed persistence, when the EJB container moves an instance from the pooled state to the ready state, it does not automatically set the primary key. Therefore, the ejbCreate and ejbActivate methods must set the primary key.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.254