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-One Self Relationship

Some object models require a class to reference another instance of the same class. In the advanced tutorial, the Manager attribute in the Employee class references another employee (see Figure B-1).

To map the manager attribute:

  1. One to one mapping button.
    Description of the illustration 11mapbtn.gif

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

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

  2. Use the Reference Descriptor drop-down list on the General tab to choose Employee as the reference descriptor.

Figure B-32 One-to-One Mapping General Tab

Description of 11mpmgr.gif follows
Description of the illustration 11mpmgr.gif

  1. Select the Use Indirection option. See "Implementing Indirection in the Tutorial".

  2. Click the Table Reference tab.

Figure B-33 One-to-One Mapping Table Reference Tab

Description of 11manref.gif follows
Description of the illustration 11manref.gif

  1. Create a new table reference by clicking the New button.

  2. In the New Reference dialog box, create a reference whose:

    • Name is EMPLOYEE_EMPLOYEE

    • Source table is EMPLOYEE

    • Target database is EMPLOYEE


      Note:

      If you leave the Name field blank, then TopLink automatically names the table as <SourceTable>_<TargetTable>.

  3. Select EMPLOYEE_EMPLOYEE (created in step 0 from the Table Reference drop-down list.

  4. Click the Add button to define the foreign key fields.

    • In the Source Field column, choose MANAGER_ID (foreign key) field.

    • In the Target Field column, choose EMP_ID (primary key) field.

    • Leave the Target Foreign Key option unchecked.


      Note:

      The mapping is from the EMPLOYEE table, MANAGER_ID field to the EMP_ID field.

  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-one Mappings

The Advanced tutorial also includes a one-to-one mapping for the following attributes:

  • address attribute in the Employee descriptor

  • owner attribute in the PhoneNumber descriptor

  • teamLeader attribute in the BaseProject descriptor

Create these mappings as shown in "Creating One-to-One Mappings Between Objects". Refer to Table B–14 for the correct relationships. Enable indirection for each of these mappings, as "Implementing Indirection in the Tutorial" indicates.