<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0" 
         xmlns="http://docbook.org/ns/docbook" 
         xmlns:xlink="http://www.w3.org/1999/xlink" 
         xmlns:xi="http://www.w3.org/2001/XInclude" 
         xmlns:svg="http://www.w3.org/2000/svg" 
         xmlns:mml="http://www.w3.org/1998/Math/MathML" 
         xmlns:html="http://www.w3.org/1999/xhtml" 
         xmlns:db="http://docbook.org/ns/docbook" 
         xml:lang="en" 
         xml:id="ejb2.entity.desc">

  <info><title>EJB 2.1 Entity Beans Description</title></info>
  

  <section xml:id="ejb2.entity.intro"><info><title>Introduction</title></info>
    

    <para>An Entity Bean is composed of the following parts, which are
    developed by the Enterprise Bean Provider:</para>

    <itemizedlist>
      <listitem>
        <para>The <emphasis>Component Interface</emphasis> is the client view
        of the bean. It contains all the "business methods" of the
        bean.</para>
      </listitem>

      <listitem>
        <para>The <emphasis>Home Interface</emphasis> contains all the methods
        for the bean life cycle (creation, suppression) and for instance
        retrieval (finding one or several bean objects) used by the client
        application. It can also contain methods called "home methods,"
        supplied by the bean provider, for business logic which are not
        specific to a bean instance.</para>
      </listitem>

      <listitem>
        <para>The <emphasis>Primary Key </emphasis>class (for entity beans
        only) contains a subset of the bean's fields that identifies a
        particular instance of an entity bean. This class is optional since
        the bean programmer can alternatively choose a standard class (for
        example, java.lang.String)</para>
      </listitem>

      <listitem>
        <para>The <emphasis>bean implementation</emphasis> class implements
        the business methods and all the methods (described in the EJB
        specification) allowing the bean to be managed in the
        container.</para>
      </listitem>

      <listitem>
        <para>The <emphasis>deployment descriptor</emphasis>, containing the
        bean properties that can be edited at assembly or deployment
        time.</para>
      </listitem>
    </itemizedlist>

    <para>Note that, according to the EJB 2.1 specification, the couple
    <emphasis>Component Interface</emphasis> and <emphasis>Home
    Interface</emphasis> may be either local or remote. <emphasis>Local
    Interfaces</emphasis> (Home and Component) are to be used by a client
    running in the same JVM as the EJB component. Create and finder methods of
    a local or remote home interface return local or remote component
    interfaces respectively. An EJB component can have both remote and local
    interfaces, even if typically only one type of interface is
    provided.</para>

    <para>The description of these elements is provided in the following
    sections.</para>

    <note>
      <para>in this documentation, the term "Bean" always means "Enterprise
      Bean."</para>
    </note>

    <para>An entity bean represents persistent data. It is an object view of
    an entity stored in a relational database. The persistence of an entity
    bean can be handled in two ways:</para>

    <itemizedlist>
      <listitem>
        <para><emphasis>Container-Managed Persistence</emphasis>: the
        persistence is implicitly managed by the container, no code for data
        access is supplied by the bean provider. The bean's state will be
        stored in a relational database according to a mapping description
        delivered within the deployment descriptor (CMP 1) or according to an
        implicit mapping (CMP 2).</para>
      </listitem>

      <listitem>
        <para><emphasis>Bean-Managed Persistence</emphasis>: the bean provider
        writes the database access operations (JDBC code) in the methods of
        the enterprise bean that are specified for data creation, load, store,
        retrieval, and remove operations (ejbCreate, ejbLoad, ejbStore,
        ejbFind..., ejbRemove).</para>
      </listitem>
    </itemizedlist>

    <para>Currently, the platform handles persistence in relational storage
    systems through the JDBC interface. For both container-managed and
    bean-managed persistence, JDBC connections are obtained from an object
    provided at the EJB server level, the DataSource. The DataSource interface
    is defined in the JDBC 2.0 standard extensions. A DataSource object
    identifies a database and a means to access it via JDBC (a JDBC driver).
    An EJB server may propose access to several databases and thus provides
    the corresponding DataSource objects. DataSources are described in more
    detail in the section<xref linkend="config.jdbc"/></para>
  </section>

  <section xml:id="ejb2.entity.home"><info><title>The Home Interface</title></info>
    

    <para>In addition to home business methods, the <classname>Home
    interface</classname> is used by any client application to create, remove,
    and retrieve instances of the entity bean. The bean provider only needs to
    provide the desired interface; the container will automatically provide
    the implementation. The interface must extend the
    <interfacename>javax.ejb.EJBHome</interfacename> interface if it is
    remote, or the <interfacename>javax.ejb.EJBLocalHome</interfacename>
    interface if it is local. The methods of a remote home interface must
    follow the rules for java RMI. The signatures of the
    <methodname>create</methodname> and <methodname>finder
    methods</methodname> should match the signatures of the
    <methodname>ejbCreate</methodname> and <methodname>ejbFinder</methodname>
    methods that will be provided later in the enterprise bean implementation
    class (same number and types of arguments, but different return
    types).</para>

    <section xml:id="ejb2.entity.home.create"><info><title>create methods</title></info>
      

      <itemizedlist>
        <listitem>
          <para>The return type is the enterprise bean's component
          interface.</para>
        </listitem>

        <listitem>
          <para>The exceptions defined in the throws clause must include the
          exceptions defined for the ejbCreate and ejbPostCreate methods, and
          must include javax.ejb.CreateException and java.rmi.RemoteException
          (the latter, only for a remote interface).</para>
        </listitem>
      </itemizedlist>
    </section>

    <section xml:id="ejb2.entity.home.remove"><info><title>remove methods</title></info>
      

      <itemizedlist>
        <listitem>
          <para>The interfaces for these methods must not be defined, they are
          inherited from EJBHome or EJBLocalHome.</para>
        </listitem>
      </itemizedlist>

      <itemizedlist>
        <listitem>
          <para>The method is void remove taking as argument the primary key
          object or the handle (for a remote interface).</para>
        </listitem>
      </itemizedlist>

      <itemizedlist>
        <listitem>
          <para>The exceptions defined in the throws clause should be
          javax.ejb.RemoveException and java.ejb.EJBException for a local
          interface.</para>
        </listitem>
      </itemizedlist>

      <itemizedlist>
        <listitem>
          <para>The exceptions defined in the throws clause should be
          javax.ejb.RemoveException and java.rmi.RemoteException for a remote
          interface.</para>
        </listitem>
      </itemizedlist>
    </section>

    <section xml:id="ejb2.entity.home.finder"><info><title>finder methods</title></info>
      

      <para>Finder methods are used to search for an EJB object or a
      collection of EJB objects. The arguments of the method are used by the
      entity bean implementation to locate the requested entity objects. For
      bean-managed persistence, the bean provider is responsible for
      developing the corresponding ejbFinder methods in the bean
      implementation. For container-managed persistence, the bean provider
      does not write these methods; they are generated at deployment time by
      the platform tools; the description of the method is provided in the
      deployment descriptor, as defined in the section 
      <xref linkend="ejb.config.db.cmp2"/>
      In the Home interface, the
      finder methods must adhere to the following rules:</para>
    <itemizedlist>
      <listitem><para>
        They must be named "
        find&lt;method&gt;
        " (e.g.     
        <function>
          findLargeAccounts
        </function>
        ).</para>
      </listitem>
      <listitem><para>
        The return type must be the enterprise bean's component interface, or a     collection thereof.</para>
      </listitem>
      <listitem><para>
        The exceptions defined in the throws clause must include the exceptions     defined for the matching ejbFind method, and must include     
        <literal>
          javax.ejb.FinderException
        </literal>
         and 
        <literal>
          java.rmi.RemoteException
        </literal>
             (the latter, only for a remote interface).</para>
      </listitem>
    </itemizedlist><para>
     At least one of these methods is mandatory: 
    findByPrimaryKey
    , which takes as argument a primary key value and returns the corresponding EJB object.  </para>
    <para>
      home methods:
    </para>
    <itemizedlist>
      <listitem><para>
        Home methods are methods that the bean provider supplies for business     logic that is not specific to an entity bean instance.</para>
      </listitem>
      <listitem><para>
        The throws clause of every home method on the remote home interface     includes the java.rmi.RemoteException.</para>
      </listitem>
      <listitem><para>
        Home methods implementation is provided by the bean developer in the     bean implementation class as public static methods named     
        <literal>
          ejbHome&lt;METHOD_NAME&gt;(...)
        </literal>
        , where &lt;METHOD_NAME&gt; is     the name of the method in the home interface.</para>
      </listitem>
    </itemizedlist>
	</section>
    <section xml:id="ejb2.entity.home.example"><info><title>Example</title></info>
      <para>
       The Account bean example, provided with the platform examples, is used to illustrate these concepts. The state of an entity bean instance is stored in a relational database, where the following table should exist, if CMP 1.1 is used:  </para>
      <screen>create table ACCOUNT (ACCNO integer primary key, CUSTOMER varchar(30), BALANCE number(15,4));
      </screen>
      <screen>
public interface AccountHome extends EJBHome {
    public Account create(int accno, String customer, double balance) throws RemoteException, CreateException;
    public Account findByPrimaryKey(Integer pk) throws RemoteException, FinderException;
    public Account findByNumber(int accno) throws RemoteException, FinderException;
    public Enumeration findLargeAccounts(double val) throws RemoteException, FinderException;
}     </screen>
    </section>
  </section>
  <section xml:id="ejb2.entity.component"><info><title>The Component Interface</title></info>
    <para>
    Business methods:</para>
    <para>
      The Component Interface is the client's view of an instance of the entity bean. It is what is returned to the client by the Home interface after creating or finding an entity bean instance. This interface contains the business methods of the enterprise bean. The interface must extend the 
      <literal>
        javax.ejb.EJBObject
      </literal>
       interface if it is remote, or the 
      <literal>
        javax.ejb.EJBLocalObject
      </literal>
       if it is local. The methods of a remote component interface must follow the rules for java RMI. For each method defined in this component interface, there must be a matching method of the bean implementation class (same arguments number and types, same return type, same exceptions except for RemoteException).
    </para>
    <section xml:id="ejb2.entity.component.example">
      <info><title>Example</title></info>
      
      <screen>
public interface Account extends EJBObject {
    public double getBalance() throws RemoteException;
    public void setBalance(double d) throws RemoteException;
    public String getCustomer() throws RemoteException;
    public void setCustomer(String c) throws RemoteException;
    public int getNumber() throws RemoteException;
}     </screen>
    </section>
  </section>
  <section xml:id="ejb2.entity.pk"><info><title>The Primary Key Class</title></info>
    <para>
     The Primary Key class is necessary for entity beans only. It encapsulates the fields representing the primary key of an entity bean in a single object. If the primary key in the database table is composed of a single column with a basic data type, the simplest way to define the primary key in the bean is to use a standard java class (for example, 
    <literal>
      java.lang.Integer
    </literal>
     or 
    <literal>
      java.lang.String
    </literal>
    ). This must have the same type as a field in the bean class. It is not possible to define it as a primitive field (for example, int, float or boolean). Then, it is only necessary to specify the type of the primary key in the deployment descriptor: </para>
    <screen>
 &lt;prim-key-class&gt;java.lang.Integer&lt;/prim-key-class&gt;    </screen>
     <para>
     And, for container-managed persistence, the field which represents the primary key: </para>
    <screen>
 &lt;primkey-field&gt;accno&lt;/primkey-field&gt;    </screen>
     <para>
     The alternative way is to define its own Primary Key class, described as follows:  </para>
    <para>
      The class must be serializable and must provide suitable implementation of the 
      <literal>
        hashcode()
      </literal>
       and 
      <literal>
        equals(Object)
      </literal>
       methods.
    </para>
    <para>
      For 
      container-managed persistence
      , the following rules must be followed:
    </para>
    <itemizedlist>
      <listitem><para>
        The fields of the primary key class must be declared as public.</para>
      </listitem>
      <listitem><para>
        The primary key class must have a public default constructor.</para>
      </listitem>
      <listitem><para>
        The names of the fields in the primary key class must be a subset of     the names of the container-managed fields of the enterprise bean.</para>
      </listitem>
    </itemizedlist>
    <section>
      <info><title>Example</title></info>
      <para>
      <screen>
public class  AccountBeanPK implements java.io.Serializable {
    public int accno;
    public AccountBeanPK(int accno) { this.accno = accno; }
    public AccountBeanPK() { }
    public int hashcode() { return accno; }
    public boolean equals(Object other) {
        ...
    }
}
      </screen></para>
    </section>
    <section xml:id="ejb2.entity.pk.auto">
      <info><title>Special case: Automatic generation of primary key fields</title></info>
      
      <para>
        There are two ways to manage the automatic primary key with JOnAS. The first method is closer to what is described in the EJB specification, i.e. an automatic PK is a hidden field, the type of which is not known even by the application. The second method is to declare a usual PK CMP field of type java.lang.Integer as automatic. The two cases are described below.
      </para>
      <orderedlist>
        <listitem><para>Standard automatic primary keys</para>
        
        <para>
          In this case, an automatic PK is a hidden field, the type of which is not known even by the application. All that is necessary is to stipulate in the standard deployment descriptor that this EJB has an automatic PK, by specifying java.lang.Object as primkey-class. The primary key will be completely hidden to the application (no CMP field, no getter/setter method). This is valid for both CMP 2.x and CMP1 entity beans. The container will create an internal CMP field and generate its value when the entity bean is created.
        </para>
        <para>
          Example:
        </para>
        <para>
          Standard deployment descriptor:
        </para>
        <screen>
  &lt;entity&gt;
    ...
    &lt;ejb-name&gt;AddressEJB&lt;/ejb-name&gt;
    &lt;local-home&gt;com.titan.address.AddressHomeLocal&lt;/local-home&gt;
    &lt;local&gt;com.titan.address.AddressLocal&lt;/local&gt;
    &lt;ejb-class&gt;com.titan.address.AddressBean&lt;/ejb-class&gt;
    &lt;persistence-type&gt;Container&lt;/persistence-type&gt;
    &lt;prim-key-class&gt;java.lang.Object&lt;/prim-key-class&gt;
    &lt;reentrant&gt;False&lt;/reentrant&gt;
    &lt;cmp-version&gt;2.x&lt;/cmp-version&gt;
    &lt;abstract-schema-name&gt;Cmp2_Address&lt;/abstract-schema-name&gt;
    &lt;cmp-field&gt;&lt;field-name&gt;street&lt;/field-name&gt;&lt;/cmp-field&gt;
    &lt;cmp-field&gt;&lt;field-name&gt;city&lt;/field-name&gt;&lt;/cmp-field&gt;
    &lt;cmp-field&gt;&lt;field-name&gt;state&lt;/field-name&gt;&lt;/cmp-field&gt;
    &lt;cmp-field&gt;&lt;field-name&gt;zip&lt;/field-name&gt;&lt;/cmp-field&gt;        </screen>
        <para>
          Address Bean Class extract:
        </para>
        <screen>
   // Primary key is not explicitly initialized during ejbCreate method
   // No cmp field corresponds to the primary key
   public Integer ejbCreateAddress(String street, String city,
        String state, String zip ) throws javax.ejb.CreateException {
     setStreet(street);
     setCity(city);
     setState(state);
     setZip(zip);
     return null;
   }        </screen>
        <para>
          If nothing else is specified, and the JOnAS default CMP 2 database mapping is used, the JOnAS container will generate a database column with name JPK_ to handle this PK. However, it is possible to specify in the JOnAS-specific Deployment Descriptor the name of the column that will be used to store the PK value in the table, using the specific &lt;automatic-pk-field-name&gt; element, as follows (this is necessary for CMP2 legacy and for CMP1):
        </para>
        <para>
          JOnAS-specific deployment descriptor:
        </para>
        <screen>
  &lt;jonas-ejb-jar xmlns="http://www.objectweb.org/jonas/ns"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.objectweb.org/jonas/ns http://www.objectweb.org/jonas/ns/jonas-ejb-jar_4_0.xsd" &gt;
  &lt;jonas-entity&gt;
     &lt;ejb-name&gt;AddressEJB&lt;/ejb-name&gt;
     &lt;jdbc-mapping&gt;
        &lt;jndi-name&gt;jdbc_1&lt;/jndi-name&gt;
        &lt;automatic-pk-field-name&gt;FieldPkAuto&lt;/automatic-pk-field-name&gt;
     &lt;/jdbc-mapping&gt;
  &lt;/jonas-entity&gt;        </screen>
      </listitem>
      <listitem><para>CMP field as automatic primary key</para>
        
        <para>
          The idea is to declare a usual PK CMP field of type java.lang.Integer as automatic, then it no longer appears in create methods and its value is automatically generated by the container at EJB instance creation time. But it is still a cmp field, with getter/setter methods, accessible from the application. Example:
        </para>
        <para>
          In the standard DD, there is a usual primary key definition,
        </para>
        <screen>
  &lt;entity&gt;
     ...
     &lt;prim-key-class&gt;java.lang.Integer&lt;/prim-key-class&gt;
     &lt;cmp-field&gt;&lt;field-name&gt;id&lt;/field-name&gt;&lt;/cmp-field&gt;
     &lt;primkey-field&gt;id&lt;/primkey-field&gt;        </screen>
        <para>
          and in the JOnAS-specific Deployment Descriptor, it should be specified that this PK is automatic,
        </para>
        <screen>
  &lt;jonas-entity&gt;
     ...
     &lt;jdbc-mapping&gt;

     &lt;automatic-pk&gt;true&lt;/automatic-pk&gt;        </screen>
        <para>
           Note: The automatic primary key is given a unique ID by an algorithm that is based on the system time; therefore, IDs may be not sequential. 
        </para>
        <para>
           Important restriction: This algorithm will not work if used inside a cluster with the same entity bean that is being managed in several jonas servers. 
        </para>
        </listitem>
      </orderedlist>
    </section>
  </section>

  <section xml:id="ejb2.entity.bean"><info><title>The Enterprise Bean Class</title></info>
    <para>
     The EJB implementation class implements the bean's business methods of the component interface and the methods dedicated to the EJB environment, the interface of which is explicitly defined in the EJB specification. The class must implement the 
    <literal>
      javax.ejb.EntityBean
    </literal>
     interface, must be defined as public, cannot be 
    abstract
     for CMP 1.1, and must be abstract for CMP 2.0 (in this case, the abstract methods are the get and set accessor methods of the bean cmp and cmr fields). Following is a list of the EJB environment dedicated methods that the EJB provider must develop.  </para>
    <para>
      The first set of methods are those corresponding to the create and find methods of the Home interface:
    </para>
    <itemizedlist>
      <listitem>
        <para><function>public PrimaryKeyClass ejbCreate(...);</function></para>
        <para>
          This method is invoked by the container when a client invokes the     corresponding create operation on the enterprise Bean's home interface.     The method should initialize instance's variables from the input     arguments. The returned object should be the primary key of the created     instance. For bean-managed persistence, the bean provider should develop     here the JDBC code to create the corresponding data in the database. For     container-managed persistence, the container will perform the database     insert 
          after
           the ejbCreate method completes and the return value     should be 
          null
          .
        </para>
      </listitem>
      <listitem><para><function>public void ejbPostCreate(...);</function></para>
        <para>
          There is a matching ejbPostCreate method (same input parameters) for     each ejbCreate method. The container invokes this method after the     execution of the matching ejbCreate(...) method. During the ejbPostCreate     method, the object identity is available.
        </para>
      </listitem>
      <listitem><para><function>
        public
         &lt;PrimaryKeyClass or Collection&gt;
        ejbFind&lt;method&gt;
         (...);</function> // bean-managed persistence     only</para>
        <para>
          The container invokes this method on a bean instance that is not     associated with any particular object identity (some kind of class method     ...) when the client invokes the corresponding method on the Home     interface. The implementation uses the arguments to locate the requested     object(s) in the database and returns a primary key (or a collection     thereof). Currently, collections will be represented as     
          <classname>
            java.util.Enumeration 
          </classname>
           or     
          <classname>
            java.util.Collection
          </classname>
          . The mandatory 
          <function>FindByPrimaryKey</function>
               method takes as argument a primary key type value and returns a primary     key object (it verifies that the corresponding entity exists in the     database). 
          For container-managed persistence
          , the bean provider     does not have to write these finder methods; they are generated at     deployment time by the EJB platform tools. The information needed by the     EJB platform for automatically generating these finder methods should be     provided by the bean programmer. 
The EJB 1.1 specification does not     specify the format of this finder method description; for 
          JOnAS
          ,     the CMP 1.1 finder methods description should be provided in the     JOnAS-specific deployment descriptor of the Entity Bean (as an SQL query). Refer to the section
          <xref linkend="ejb.config.db.cmp2" />. 
The EJB 2.0     specification defines a standard way to describe these finder methods,     i.e. in the standard deployment descriptor, as an EJB-QL query. Also     refer to the section
          <xref linkend="ejb.config.db.cmp2" />. 
Then, the methods     of the 
          <classname>
            javax.ejb.EntityBean
          </classname>
           interface must be implemented:
        </para>
        <itemizedlist>
          <listitem><para><function>
            public void
            setEntityContext
            (EntityContext ic);</function></para>
            <para>
              Used by the container to pass a reference to the EntityContext to         the bean instance. The container invokes this method on an instance         after the instance has been created. Generally, this method is used         to store this reference in an instance variable.
            </para>
          </listitem>
          <listitem><para><function>
            public void
            unSetEntityContext
            ();</function></para>
            <para>
              Unset the associated entity context. The container calls this         method before removing the instance. This is the last method the         container invokes on the instance.
            </para>
          </listitem>
          <listitem><para><function>
            public void
            ejbActivate
            ();</function></para>
            <para>
              The container invokes this method when the instance is taken out         of the pool of available instances to become associated with a         specific EJB object. This method transitions the instance to the         ready state.
            </para>
          </listitem>
          <listitem><para><function>
            public void
            ejbPassivate
            ();</function></para>
            <para>
              The container invokes this method on an instance before the         instance becomes dissociated with a specific EJB object. After this         method completes, the container will place the instance into the pool         of available instances.
            </para>
          </listitem>
          <listitem><para><function>
            public void
            ejbRemove
            ();</function></para>
            <para>
              This method is invoked by the container when a client invokes a         remove operation on the enterprise bean. For entity beans with         
              bean-managed persistence
              , this method should contain the JDBC         code to remove the corresponding data in the database. For         
              container-managed persistence
              , this method is called         
              before
               the container removes the entity representation in the         database.
            </para>
          </listitem>
          <listitem><para><function>
            public void
            ejbLoad
            ();</function></para>
            <para>
              The container invokes this method to instruct the instance to         synchronize its state by loading it from the underlying database. For         
              bean-managed persistence
              , the EJB provider should code at this         location the JDBC statements for reading the data in the database.         For 
              container-managed persistence
              , loading the data from the         database will be done automatically by the container just         
              before
               ejbLoad is called, and the ejbLoad method should only         contain some "after loading calculation statements."
            </para>
          </listitem>
          <listitem><para><function>
            public void
            ejbStore
            ();</function></para>
            <para>
              The container invokes this method to instruct the instance to         synchronize its state by storing it to the underlying database. For         
              bean-managed persistence
              , the EJB provider should code at this         location the JDBC statements for writing the data in the database.         For entity beans with 
              container-managed persistence
              , this         method should only contain some "pre-store statements," since the         container will extract the container-managed fields and write them to         the database just 
              after
               the ejbStore method call.
            </para>
          </listitem>
        </itemizedlist>
      </listitem>
    </itemizedlist>
    <section xml:id="ejb2.entity.bean.example"><info><title>Example</title></info>
      
      <para>
        The following examples are for container-managed persistence with EJB 1.1 and EJB 2.0. For bean-managed persistence, refer to the examples delivered with your specific platform.
      </para>
      <section><info><title>CMP 1.1</title></info>
      <screen>
package eb;

import java.rmi.RemoteException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.RemoveException;
import javax.ejb.EJBException;

public class AccountImplBean implements EntityBean {

  // Keep the reference on the EntityContext
  protected EntityContext entityContext;

  // Object state
  public Integer accno;
  public String customer;
  public double balance;

  public Integer ejbCreate(int val_accno, String val_customer, double val_balance) {

    // Init object state
    accno = new Integer(val_accno);
    customer = val_customer;
    balance = val_balance;
    return null;
  }

  public void ejbPostCreate(int val_accno, String val_customer, double val_balance) { 
    // Nothing to be done for this simple example.
  }

  public void ejbActivate() {
    // Nothing to be done for this simple example.
  }

  public void ejbLoad() {
    // Nothing to be done for this simple example, in implicit persistence.
  }

  public void ejbPassivate() {
    // Nothing to be done for this simple example.
  }


  public void ejbRemove() {
    // Nothing to be done for this simple example, in implicit persistence.
  }

  public void ejbStore() {
    // Nothing to be done for this simple example, in implicit persistence.
  }

  public void setEntityContext(EntityContext ctx) {
    // Keep the entity context in object
    entityContext = ctx;
  }

  public void unsetEntityContext() {
    entityContext = null;
  }

  public double getBalance() {
    return balance;
  }

  public void setBalance(double d) {
    balance = balance + d;
  }

  public String  getCustomer() {
    return customer;
  }

  public void setCustomer(String c) {
    customer = c;
  }

  public int getNumber()  {
    return accno.intValue();
  }
}      </screen>
      </section>
      <section><info><title>CMP 2.0</title></info>
      <screen>
import java.rmi.RemoteException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.RemoveException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;

public abstract class AccountImpl2Bean implements EntityBean {

  // Keep the reference on the EntityContext
  protected EntityContext entityContext;


  /*========================= Abstract set and get accessors for cmp fields ==============*/

  public abstract String getCustomer();
  public abstract void setCustomer(String customer);

  public abstract double getBalance();
  public abstract void setBalance(double balance);

  public abstract int getAccno();
  public abstract void setAccno(int accno);

  /*========================= ejbCreate methods ============================*/


  public Integer ejbCreate(int val_accno, String val_customer, double val_balance) 
  throws CreateException {

    // Init object state
    setAccno(val_accno);
    setCustomer(val_customer);
    setBalance(val_balance);
    return null;
  }
 
  public void ejbPostCreate(int val_accno, String val_customer, double val_balance) { 
    // Nothing to be done for this simple example.
  }


  /*====================== javax.ejb.EntityBean implementation =================*/

  public void ejbActivate() {
    // Nothing to be done for this simple example.
  }

  public void ejbLoad() {
    // Nothing to be done for this simple example, in implicit persistence.
  }

  public void ejbPassivate() {
    // Nothing to be done for this simple example.
  }

  public void ejbRemove() throws RemoveException {
    // Nothing to be done for this simple example, in implicit persistence.
  }

  public void ejbStore() {
    // Nothing to be done for this simple example, in implicit persistence.
  }
 
  public void setEntityContext(EntityContext ctx) { 

    // Keep the entity context in object
    entityContext = ctx;
  }

  public void unsetEntityContext()  {
    entityContext = null;
  }

  /**
  * Business method to get the Account number
  */
  public int getNumber()  {
    return getAccno();
  }
}
      </screen>
      </section>
    </section>
  </section>

</section>