|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
You do not define CMR fields in the entity bean class: CMR fields are virtual only. OC4J supplies the implementation of the CMR fields.
You must define public, abstract get and set methods for the CMR fields in the local interface of the related entity bean, 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 assign an entity bean local interface type (or a collection of such) to a CMR field.
You must specify container-managed relationship fields in the ejb-jar.xml deployment descriptor using the cmr-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 container-managed relationship field (cmr-field) that is specified in the deployment descriptor, and in which the first letter of the name of the cmr-field has been upper cased and prefixed by get or set.
The accessor methods for CMR fields for one-to-many or many-to-many relationships must utilize one of the following collection interfaces: java.util.Collection or java.util.Set. The collection interfaces used in relationships are specified in the deployment descriptor. The implementation of the collection classes used for the CMR fields is supplied by the container. The collection classes that are used for container-managed relationships must not be exposed through the remote interface of the entity bean.
For more information, see:
Example 14-10 shows the abstract get and set methods for the CMR fields specified in the ejb-jar.xml file (see "Using Deployment XML").
Example 14-10 EJB 2.1 Container-Managed Relationship 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);
public abstract void setProjects(Collection projects);
public abstract Collection getProjects();
...
}
Example 14-11 shows the cmr-field elements for the get and set methods specified in the bean class (see "Using Java").
Example 14-11 ejb-jar.xml for an EJB 2.1 CMR Field
... <relationships> <ejb-relation> <ejb-relation-name>Topic-Faqs</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>Topic-has-Faqs</ejb-relationship-role-name> <multiplicity>Many</multiplicity> <relationship-role-source> <ejb-name>TopicBean</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>faqs</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relation> ... <relationships>