Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
You do not define container-managed persistent fields in the entity bean class: container-managed persistent fields are virtual only. OC4J supplies the implementation of the container-managed persistent fields.
You must define public
, abstract
getter and setter methods for the container-managed persistent fields, using the EJB conventions (see "Using Java"). OC4J supplies the implementation of these methods. You must not expose these getter and setter methods in the remote interface of the entity bean.
You may assign only the following Java types to container-managed persistent 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 container-managed persistent 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
.
Note:
In this release,orion-ejb-jar.xml
file <entity-deployment>
subelement <cmp-field-mapping>
is not used. For more information, see "<entity-deployment>".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 Persistent Fields?".
Example 14-4 shows the abstract getter and setter methods for the container-managed persistent fields specified in the ejb-jar.xml
file (see "Using Deployment XML").
Example 14-4 EJB 2.1 Container-Managed Persistent Fields
package cmpapp; import javax.ejb.*; import java.rmi.*; public abstract class EmployeeBean implements EntityBean { private EntityContext ctx; // container-managed persistent 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); ... }
Example 14-5 shows the cmp-field
elements for the getter and setter methods specified in the bean class (see "Using Java").
Example 14-5 ejb-jar.xml for an EJB 2.1 Container-Managed Persistent 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>