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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access