O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Life Cycle of an Entity Bean

To understand how to best develop entity beans, it is important to understand how the container manages them. The EJB specification defines just about every major event in an entity bean’s life, from the time it is instantiated to the time it is garbage collected. This is called the life cycle, and it provides the bean developer and EJB vendors with all the information they need to develop beans and EJB servers that adhere to a consistent protocol. To understand the life cycle, we will follow an entity instance through several life-cycle events and describe how the container interacts with the entity bean during these events. Figure 10-2 illustrates the life cycle of an entity instance.

Entity bean life cycle

Figure 10-2. Entity bean life cycle

This section identifies the points at which the container calls each of the methods described in the EntityBean interface as well as the find methods and the select and home methods. Bean instances must implement the EntityBean interface, which means that invocations of the callback methods are invocations on the bean instance itself.

At each stage of the entity bean’s life cycle, the bean container provides varying levels of access. For example, the EntityContext.getPrimaryKey( ) method will not work if it is invoked in the ejbCreate( ) method, but it does work when called in the ejbPostCreate( ) method. Other EJBContext methods have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required