| Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
In a one-to-many relationship, an entity bean instance is related to multiple instances of another entity bean.
You specify a container-managed one-to-many 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-9 shows the pair of <ejb-relationship-role> elements that define a one-to-many bidirectional relationship between Order and LineItem. For a unidirectional relationship, you would omit the cmr-field from the appropriate <ejb-relationship-role> element.
Example 14-9 ejb-jar.xml for an EJB 2.1 Bidirectional One-to-Many Relationship
...
<relationships>
<ejb-relation>
<ejb-relation-name>Order-LineItem</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>order-has-lineitems</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>OrderEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>lineItems</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>lineitem-belongsto-order</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<cascade-delete/>
<relationship-role-source>
<ejb-name>LineItemEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>order</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
...
<relationships>