user manual
Chapter 15: Entity Beans and Table Mapping for CMP 2.0 161
Container-Managed Persistence in Borland Enterprise Server
field> element containing the relationship. The descriptor then uses <table-
ref> elements to specify relationships between two tables, a <left-table> and
a <right-table>. You must observe the following cardinalities:
■
One <ejb-relationship-role> must be defined per direction; if you have a bi-
directional relationship, you must define an <ejb-relationship-role> for each
bean with each referencing the other.
■
Only one <table-ref> element is permitted per relationship.
Within the <left-table> and <right-table> elements, you specify a column list
that contains the column names to be linked together. The column list
corresponds to the <column-list> element in the descriptor. The XML is:
<!ELEMENT column-list (column-name+)>
Let's look at some relationships to see how this XML is put into practice:
CASE 1: a unidirectional one-to-one relationship.
Here, we have a Customer entity bean with a primary key, CUSTOMER_NO, that is
also used as a primary key for an entity called SpecialInfo, which contains
special customer information stored in a separate table. We need to specify a
relationship between these two entities. The Customer entity uses a field called
specialInformation to map to the SpecialInfo bean. We specify two relationship
roles, one for each bean and assign either to left- and/or right-table. Then we
specify the name of their related column for both.
<relationships>
<ejb-relation>
<ejb-relationship-role>
<relationship-role-source>
<ejb-name>Customer</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>specialInformation</cmr-field-name>
<table-ref>
<left-table>
<table-name>CUSTOMER</table-name>
<column-list>CUSTOMER_NO</column-list>
</left-table>
<right-table>
<table-name>SPECIAL_INFO</table-name>
<column-list>CUSTOMER_NO</column-list>
</right-table>
</table-ref>
</cmr-field>
</ejb-relationship-role>
Next, we finish the <ejb-relation> entry by providing its other half, the
SpecialInfo bean. Since this is a mono-directional relationship, we don't need
to specify any table elements. We only need add the following, defining the
other half of the relationship and its source:










