8.9. Standard CMP2.0 Aspects

This section briefly describes the new features available in CMP2.0 as compared to CMP 1.1, and how these features change the development of Entity Beans.

8.9.1. Entity Bean Implementation Class

The EJB implementation class:

The class must implement the javax.ejb.EntityBean interface, be defined as public, and be abstract (which is not the case for CMP1.1, where it must not be abstract). The abstract methods are the get and set accessor methods of the bean cmp and cmr fields. Refer to the examples and details in Chapter 8 Developing Entity Beans.

8.9.2. Standard Deployment Descriptor

The standard way to indicate to an EJB platform that an Entity Bean has container-managed persistence is to fill the <persistence-type> tag of the deployment descriptor with the value container, and to fill the <cmp-field> tags of the deployment descriptor with the list of container-managed fields (the fields that the container will have in charge to make persistent) and the <cmr-field> tags identifying the relationships. The CMP version (1.x or 2.x) should also be specified in the <cmp-version> tag. This is represented by the following lines in the deployment descriptor:

    
<persistence-type>container</persistence-type>
<cmp-version>1.x</cmp-version>
<cmp-field>
  <field-name>fieldOne</field-name>
</cmp-field>
<cmp-field>
  <field-name>fieldTwo</field-name>
</cmp-field>

WarningWarning
 

To run CMP1.1-defined Entity Beans on an EJB2.0 platform, such as JOnAS 3.x, you must introduce the <cmp-version> element in your deployment descriptors, because the default cmp-version value (if not specified) is 2.x.

Note that for CMP 2.0, the information defining the behavior of the implementation of a find<method> method is located in the standard deployment descriptor as an EJB-QL query (this is not JOnAS-specific information). For CMP 1.1, this information is located in the JOnAS-specific deployment descriptor as an SQL WHERE clause specified in a <finder-method-jdbc-mapping> element.

The following example shows a finder method in CMP 2.0 for a findLargeAccounts(double val) method defined on the Account Entity Bean of the JOnAS eb example.

      
<query>
  <query-method>
    <method-name>findLargeAccounts</method-name>
    <method-params>
        <method-param>double</method-param>
    </method-params>
  </query-method>
  <ejb-ql>SELECT OBJECT(o) FROM accountsample o 
    WHERE o.balance > ?1</ejb-ql>
</query>