Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
Descriptors can use multiple tables in mappings. Use multiple tables when:
A subclass is involved in inheritance, and its superclass is mapped to one table while the subclass has additional attributes that are mapped to a second table
A class is not involved in inheritance and its data is spread out across multiple tables
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.
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:
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.
Click the Multi-table Info tab.
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.
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.
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.
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.
Select the associated table, and select Associated Via Primary Key.
Select Primary Keys Have Different Names.
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.
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.
Select the associated table, and select Associated Via Foreign Key.
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.