JBoss.org Community Documentation
Relationships can be mapped using either a foreign key or a separate relation table. One-to-one and one-to-many relationships use the foreign key mapping style by default, and many-to-many relationships use only the relation table mapping style. The mapping of a relationship is declared in the relationships section of the jbosscmp-jdbc.xml descriptor via ejb-relation elements. Relationships are identified by the ejb-relation-name from the ejb-jar.xml file. The jbosscmp-jdbc.xml
ejb-relation element content model is shown in Figure 12.7, “The jbosscmp-jdbc.xml ejb-relation element content model”.
The basic template of the relationship mapping declaration for Organization-Gangster relationship follows:
<jbosscmp-jdbc>
<relationships>
<ejb-relation>
<ejb-relation-name>Organization-Gangster</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>org-has-gangsters</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>name</field-name>
<column-name>organization</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>gangster-belongs-to-org</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</jbosscmp-jdbc>
After the ejb-relation-name of the relationship being mapped is declared, the relationship can be declared as read only using the read-only and read-time-out elements. They have the same semantics as their counterparts in the entity element.
The ejb-relation element must contain either a foreign-key-mapping element or a relation-table-mapping element, which are described in Section 12.5.3.2, “Foreign Key Mapping” and Section 12.5.3.3, “Relation table Mapping”. This element may also contain a pair of ejb-relationship-role elements as described in the following section.