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;
    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 10, 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 in most cases the resources ...

Get Enterprise JavaBeans, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.