Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring a Many-to-Many Relationship

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".

Using Deployment XML

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>