Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
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:
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.
Use the Reference Descriptor drop-down list on the General tab to choose Employee
as the reference descriptor.
Select the Use Indirection option. See "Implementing Indirection in the Tutorial".
Click the Table Reference tab.
Create a new table reference by clicking the New button.
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> .
|
Select EMPLOYEE_EMPLOYEE
(created in step 0 from the Table Reference drop-down list.
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 theEMPLOYEE table, MANAGER_ID field to the EMP_ID field.
|
Description of the illustration savebtn.gif
Click Save on the toolbar or choose File > Save Project to save the project.
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.