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
 

Working with Multiple Tables

Descriptors can use multiple tables in mappings. Use multiple tables when:

When a descriptor has multiple tables, you must be able to join a row from the primary table to all the additional tables. By default, OracleAS TopLink assumes that the primary key of the first, or primary, table is included in the additional tables, thereby joining the tables.

OracleAS TopLink also supports custom methods for joining tables.

Specifying Multi-table Info

Use the Multi-table Info tab to define multiple tables for a descriptor in the OracleAS TopLink Mapping Workbench.

To associate multiple tables with a descriptor:

  1. In the Navigator pane, select a descriptor.

    If the Multi-table Info advanced property is not visible for the descriptor, right-click the descriptor and choose Set Advanced Properties > Multi-table Info from pop-up menu or from the Selected menu.

  2. Click the Multi-table Info tab.

    Figure 4-30 Multi-table Info Tab

    Description of multiinf.gif follows
    Description of the illustration multiinf.gif

  3. Use this table to enter data in each field:

Field Description
Primary Table The primary table for this descriptor. This field is for display only.
Additional Tables Use the Add and Remove buttons to add or remove additional tables.
Associated Via Specify if each Additional Table is associated by its Primary or Foreign key.

When associating an additional table via Primary Key, additional options appear on the Multi-table Info tab. Continue with "Primary Keys Match" or "Primary Keys are Named Differently" to assign the primary key.

Figure 4-31 Associating Multiple Tables via Primary Key

Description of multipk.gif follows
Description of the illustration multipk.gif

When associating a table via Foreign Key, additional options (shown in Figure 4–31) appear. You must choose a reference that relates the correct fields in the primary table to the primary keys in the selected table. Continue with "Tables are Related by Foreign Key in Primary Table" to assign the foreign key.

Figure 4-32 Associating Multiple Tables via Foreign Key

Description of multifk.gif follows
Description of the illustration multifk.gif

Primary Keys Match

When associating a descriptor with multiple tables in which the primary key field names are identical, you do not have to specify any additional information. Select the tables from the list of available tables on the Multi-table Info tab. The OracleAS TopLink Mapping Workbench automatically selects the Primary Keys Have the Same Names option.

Primary Keys are Named Differently

If the primary keys of the additional table(s) are the same, but they are named differently, you must specify how they relate to the primary key(s) of the default/primary table.

  1. Select the associated table, and select Associated Via Primary Key.

  2. Select Primary Keys Have Different Names.

  3. In the Primary Key Reference area (Figure 4–31), choose a table reference that relates how the primary keys of the primary table relate to the primary keys of the selected table. Use the drop-down list to select a primary key association.

Tables are Related by Foreign Key in Primary Table

If the primary keys of the additional table are not the same as the primary keys of the primary table, but are instead related to a different set of fields, you must set up a foreign key relation between the tables.

  1. Select the associated table, and select Associated Via Foreign Key.

  2. Use the drop-down list to choose a foreign key reference that relates the correct fields in the primary table to the primary keys in the selected table. Click Browse to create a reference.