Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Implementing a One-to-Many Self-Relationship

Some object models require a class to reference another instance of the same class. In the advanced tutorial, a manager can have a collection of managed employees (see Figure B-1).

To map the managedEmployee attribute:

  1. One to many mapping
    Description of the illustration 1mmapbtn.gif

    Select the Employee's managedEmployees attribute in the Navigator pane, then click the One-to-Many Mapping button on the mapping toolbar.

    The Editor pane displays the appropriate information for a one-to-many relationship to be specified.

  2. Use the Reference Descriptor drop-down list to choose Employee.

    Figure B-34 One-to-Many Mapping General Tab

    Description of 1mmanemp.gif follows
    Description of the illustration 1mmanemp.gif

  3. Select the Use Indirection option, and choose ValueHolder. See "Implementing Indirection in the Tutorial".

  4. Click the Table Reference tab. Use the Table Reference drop-down list to choose the EMPLOYEE_EMPLOYEE table (previously created in "To map the manager attribute:").

    • Click the Add button on the Table Reference tab to add a foreign key relationship.

    • Set the Source Field (foreign key) to MANAGER_ID.

    • Set the Target Field (primary key) to EMP_ID.

    Figure B-35 One-to-Many Mapping Table Reference Tab

    Description of 1mmantab.gif follows
    Description of the illustration 1mmantab.gif

  5. Save button.
    Description of the illustration savebtn.gif

    Click Save on the toolbar or choose File >  Save Project to save the project.

Creating Other One-to-Many Mappings

The Advanced tutorial also includes a one-to-many mapping for the phoneNumbers attribute in the Employee descriptor. Create this mapping as shown in "Creating One-to-Many Mappings". Refer to Table B–14 for the correct relationship.

Enable indirection for this mapping, as indicated in "Implementing Indirection in the Tutorial".