user manual

Chapter 15: Entity Beans and Table Mapping for CMP 2.0 163
Container-Managed Persistence in Borland Enterprise Server
<cmr-field>
<cmr-field-name>customers</cmr-field-name>
<table-ref>
<left-table>
<table-name>ORDER</table-name>
<column-list>
<column-name>CUSTOMER_NO</column-name>
</column-list>
</left-table>
<right-table>
<table-name>CUSTOMER</table-name>
<column-list>
<column-name>CUSTOMER_NO</column-name>
</column-list>
</right-table>
</table-ref>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
.
.
</relationships>
CASE 3: a many-to-many relationship.
If you define a many-to-many relationship, you must also have the CMP
engine create a cross-table which models a relationship between the left table
and the right table. Do this using the <cross-table> element, whose XML is:
<!ELEMENT cross-table (table-name, column-list, column-list)>
You may name this cross-table whatever you like using the <table-name>
element. The two <column-list> elements correspond to columns in the left and
right tables whose relationship you wish to model. For example, consider two
tables, EMPLOYEE and PROJECT, which have a many-to-many relationship. An
employee can be a part of multiple projects, and projects have multiple
employees. The EMPLOYEE table has three elements, an employee number
(EMP_NO), a last name (LAST_NAME), and a project ID number (PROJ_ID). The
PROJECT table contains columns for the project ID number (PROJ_ID), the project
name (PROJ_NAME), and assigned employees by number (EMP_NO).
To model the relationship between these two tables, a cross-table must be
created.. For example, to create a cross-table that shows employee names
and the names of the projects on which they are working, the <table-ref>
element would look like the following:
<table-ref>
<left-table>
<table-name>EMPLOYEE</table-name>
<column-list>
<column-name>EMP_NO</column-name>
<column-name>LAST_NAME</column-name>
<column-name>PROJ_ID</column-name>