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 Callback Methods

All entity beans (container- and bean-managed) must implement the javax.ejb.EntityBean interface. The EntityBean interface contains a number of callback methods that the container uses to alert the bean instance of various runtime events:

public interface javax.ejb.EntityBean extends javax.ejb.EnterpriseBean {
    public abstract void ejbActivate( ) throws EJBException, RemoteException;
    public abstract void ejbPassivate( ) throws EJBException, RemoteException;
    public abstract void ejbLoad( ) throws EJBException, RemoteException;
    public abstract void ejbStore( ) throws EJBException, RemoteException;
    public abstract void ejbRemove( ) throws EJBException, RemoteException,     
        RemoveException;
    public abstract void setEntityContext(EntityContext ctx) throws EJBException, 
        RemoteException;
    public abstract void unsetEntityContext( ) throws EJBException,
        RemoteException;
}

Each callback method is invoked on an entity bean instance at a specific time during its life cycle.

As described in Chapter 9, BMP beans must implement most of these callback methods to synchronize the bean’s state with the database. The ejbLoad( ) method tells the BMP bean when to read its state from the database; ejbStore( ) tells it when to write to the database; and ejbRemove( ) tells the bean when to delete itself from the database.

While BMP beans take full advantage of callback methods, CMP entity beans may not need to use all of them. The persistence of CMP entity beans is managed automatically, so ...

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