Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-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
 

Configuring Table and Field References (Foreign and Target Foreign Keys)

A foreign key is a combination of one or more database columns that reference a unique key, usually the primary key, in another table. Foreign keys can be any number of fields (similar to a primary key), all of which are treated as a unit. A foreign key and the parent key it references must have the same number and type of fields.

Mappings that extend oracle.toplink.mappings.ForeignReferenceMapping use foreign keys to find information in the database so that the target object(s) can be instantiated. For example, if every Employee has an attribute address that contains an instance of Address (which has its own descriptor and table) then, the one-to-one mapping for the address attribute would specify foreign key information to find an Address for a particular Employee.

TopLink classifies foreign keys into two categories in mappings–foreign keys and target foreign keys:

The table reference is the database table that contains the foreign key references.

Table 37-9 summarizes which relational mappings support this option.

Using TopLink Workbench, you can either import this table from your database or create it. If you import tables from the database (see "Importing Tables from a Database"), TopLink creates references that correspond to existing database constraints (if supported by the driver). You can also define references in TopLink without creating similar constraints on the database.

Using TopLink Workbench

To specify a table for a mapping reference, use this procedure:

  1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.

  2. Click the Table Reference tab. The Reference tab appears.

    Figure 37-5 Table Reference Tab, Table Reference Field

    Description of Figure 37-5 follows
    Description of "Figure 37-5 Table Reference Tab, Table Reference Field"

Use the following information to select the field references on the tab:

Field Description
Table Reference Select an existing table, or click New to create a new table reference.
Source and Target Field Click Add to create new foreign key reference.

To delete an existing key pair reference, select the Source and Target fields and click Remove.

    Source Field Select the database field from the source table for this foreign key reference.
    Target Field Select the database field from the target table for this foreign key reference.
    Target Foreign Key Specify whether or not the reference is from the target object's table back to the key from the mapping's descriptor's table.