Oracle8i Enterprise JavaBeans Developer's Guide and Reference Release 3 (8.1.7) Part Number A83725-01 |
|
An entity bean is a remote object that manages its data persistently through callback methods, which are defined in the javax.ejb.EntityBean
interface. When you implement the EntityBean
interface in your bean class, you develop each of the callback functions as designated by the type of persistence that you choose: bean-managed persistence or container-managed persistence. The container invokes the callback functions at designated times, to manage the bean and its persistent data. That is, the contract between the container and the entity bean involves in what order the callback methods are invoked and who manages the bean's persistent data.
Your bean class implements the methods of the EntityBean
interface. The javax.ejb.EntityBean
interface has the following definition:
public interface javax.ejb.EntityBean extends javax.ejb.EnterpriseBean { public abstract void ejbActivate(); public abstract void ejbLoad(); public abstract void ejbPassivate(); public abstract void ejbRemove(); public abstract void ejbStore(); public abstract void setEntityContext(EntityContext ctx); public abstract voic unsetEntityContext(); }
The container expects these methods to have the following functionality:
An entity bean is similar to a session bean in that certain callback methods, such as ejbCreate
, are invoked at specified times. Entity beans use callback functions for managing its persistent data, primary key, and context information. The following diagram shows what methods are called when an entity bean is created.
This method is used by an entity bean instance to retain a reference to its context. Entity beans have contexts that the container maintains and makes available to the beans. The bean may use the methods in the entity context to retrieve information about the bean, such as security, and transactional role. Refer to the Enterprise JavaBeans 1.1 specification for the full range of information that you can retrieve about the bean from the context.
The container invokes setEntityContext
method, after it first instantiates the bean, to enable the bean to retrieve the context. The container will never call this method from within a transaction context. If the bean does not save the context at this point, the bean will never gain access to the context.
When the container calls this method, it passes the reference of the EntityContext
object to the bean. The bean can then store the reference for later use. The following example shows the bean saving the context in the this.ctx
variable.
public void setEntityContext(EntityContext ctx) { this.ctx = ctx; Properties props = ctx.getEnvironment(); }
When the client invokes the remove method, the container invokes the following methods.
In addition, the ejbStore
and ejbLoad
methods are called for managing your persistent data. These are the most important callback methods--for bean-managed persistent beans.
ejbStore
method is called by the container whenever a transaction is about to end. Its purpose is to save the persistent data to an outside resource, such as a database.
ejbLoad
method is called by the container whenever a transaction has begun or when an entity bean is instantiated. Its purpose is to restore any persistent data that exists for this particular bean instance.
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|