Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring an EJB 2.1 CMP Entity Bean Container-Managed Persistence Field

You do not define CMP fields in the entity bean class: CMP fields are virtual only. OC4J supplies the implementation of the CMP fields.

You must define `public`, `abstract` get and set methods for the CMP fields, using the JavaBeans conventions (see "Using Java"). OC4J supplies the implementation of these methods. You must not expose these get and set methods in the remote interface of the entity bean.

You may assign only the following Java types to CMP fields: Java primitive types and Java serializable types. You may not assign an entity bean local interface type (or a collection of such) to a CMP field.

The container-managed persistent fields must be specified in the `ejb-jar.xml` deployment descriptor using the `cmp-field` element (see "Using Deployment XML"). The names of these fields must be valid Java identifiers and must begin with a lowercase letter, as determined by `java.lang.Character.isLowerCase`.

The accessor methods must bear the name of the `cmp-field` that is specified in the deployment descriptor, and in which the first letter of the name of the cmp-field has been upper cased and prefixed by `get` or `set`.

For more information, see "What are Container-Managed Persistence Fields?".

## Using Java

Example 14-8 shows the abstract get and set methods for the CMP fields specified in the `ejb-jar.xml` file (see "Using Deployment XML").

Example 14-8 EJB 2.1 Container-Managed Persistence Fields

    package cmpapp;

    import javax.ejb.*;
    import java.rmi.*;

    public abstract class EmployeeBean implements EntityBean
    {

        private EntityContext ctx;

        // cmp fields accessors
        public abstract Integer getEmpNo();
        public abstract void setEmpNo(Integer empNo);

        public abstract String getEmpName();
        public abstract void setEmpName(String empName);

        public abstract Float getSalary();
        public abstract void setSalary(Float salary);
    ...
    }

## Using Deployment XML

Example 14-9 shows the `cmp-field` elements for the get and set methods specified in the bean class (see "Using Java").

Example 14-9 ejb-jar.xml for an EJB 2.1 CMP Field

        <enterprise-beans>
            <entity>
                <ejb-name>Topic</ejb-name>
                <local-home>faqapp.TopicLocalHome</local-home>
                <local>faqapp.TopicLocal</local>
                <ejb-class>faqapp.TopicBean</ejb-class>
                <persistence-type>Container</persistence-type>
                <prim-key-class>java.lang.Integer</prim-key-class>
                <primkey-field>topicID</primkey-field>
                <reentrant>False</reentrant>
                <cmp-version>2.x</cmp-version>
                <abstract-schema-name>TopicBean</abstract-schema-name>
                <cmp-field>
                    <field-name>topicID</field-name>
                </cmp-field>
                <cmp-field>
                    <field-name>topicDesc</field-name>
                </cmp-field>
                ...
            </entity>
        </enterprise-beans>