Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
In a many-to-one relationship, multiple instances of an entity bean may be related to a single instance of another entity bean. This multiplicity is the opposite of one-to-many.
You specify a container-managed many-to-one relationship in the ejb-jar.xml
deployment descriptor (see "Using Deployment XML").
For more information, see "Configuring a Container-Managed Relationship Field for an EJB 2.1 Entity Bean With Container-Managed Persistence".
Example 14-10 shows the pair of <ejb-relationship-role>
elements that define a many-to-one bidirectional relationship between Employees
and Department
. For a unidirectional relationship, you would omit the cmr-field
from the appropriate <ejb-relationship-role>
element.
Example 14-10 ejb-jar.xml for an EJB 2.1 Bidirectional Many-to-One Relationship
... <relationships> <ejb-relation> <ejb-relation-name>Employee-Department</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>employees-belongto-dept</ejb-relationship-role-name> <multiplicity>Many</multiplicity> <relationship-role-source> <ejb-name>DepartmentEJB</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>dept</cmr-field-name> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <ejb-relationship-role-name>dept-has-employees</ejb-relationship-role-name> <multiplicity>One</multiplicity> <cascade-delete/> <relationship-role-source> <ejb-name>LineItemEJB</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>employees</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> </ejb-relation> ... <relationships>