Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
Many-to-many mappings represent relationships between a collection of source objects and a collection of target objects. In the advanced tutorial, the projects attribute uses a many-to-many-mapping (for example, many employees can have many projects).
To map a many-to-many mapping:
Expand the Employee
descriptor in the Navigator pane.
Click the projects
attribute of the Employee
descriptor.
Description of the illustration mmmapbtn.gif
Click the Many-to-many Mapping button on the mapping toolbar.
Use the Reference Descriptor drop-down list to choose the BaseProject
descriptor.
Use the Relation Table drop-down list to choose the PROJ_EMP
table (the class to map to).
Ensure that the Use Indirection field is selected. See "Implementing Indirection in the Tutorial".
Click the Source Reference tab, and add a new reference by clicking the New button.
Create a new reference named PROJ_EMP_EMPLOYEE
, with a source table of PROJE_EMP
and target table of EMPLOYEE,
and click OK.
In the Table Reference drop-down list, choose the PROJ_EMP_EMPLOYEE
reference.
Click the Add button on the Source Reference tab to add a foreign key relationship.
Set the Foreign Key field to EMP_ID
(from the PROJ_EMP table).
Set the Primary Key field to EMP_ID
(from the EMPLOYEE table).
Click the Target Reference tab, and add a new reference by clicking the New button.
In the Table Reference drop-down list, choose the PROJ_EMP_PROJECT
reference.
Click the Add button on the Source Reference tab to add a foreign key relationship.
Set the Source Field field to PROJ_ID
(from the PROJ_EMP table).
Set the Target Field field to PROJ_ID
(from the PROJECT table).
Description of the illustration savebtn.gif
Click Save on the toolbar or choose File > Save Project to save the project.