| Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
In a many-to-many relationship, entity bean instances may be related to multiple instances of each other.
You specify a container-managed many-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-11 shows the pair of <ejb-relationship-role> elements that define a many-to-many relationship between Teams and Players.
Example 14-11 ejb-jar.xml for an EJB 2.1 Many-to-Many Relationship
...
<relationships>
<ejb-relation>
<ejb-relationship-role>
<ejb-relationship-role-name>team-has-players</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>TeamEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>players</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>player-has-teams</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>PlayerEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>teams</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
...
<relationships>