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-one relationship, an entity bean instance is related to a single instance of another entity bean.
You specify a container-managed one-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-8 shows the pair of <ejb-relationship-role>
elements that define a one-to-one unidirectional relationship between Order
and ShippingAddress
. For a bidirectional relationship, you would add the appropriate cmr-field
to the <ejb-relationship-role>
for ShippingAddress
.
Example 14-8 ejb-jar.xml for an EJB 2.1 Unidirectional One-to-One Relationship
... <relationships> <ejb-relation> <ejb-relation-name>Order-ShippingAddress</ejb-relation-name> <ejb-relationship-role> <ejb-relationship-role-name>order-has-address</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>OrderEJB</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>shippingAddress</cmr-field-name> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <ejb-relationship-role-name>address-for-order</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>AddressEJB</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation> ... <relationships>