Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
|
Previous |
Next |
Descriptors can use multiple tables in mappings. Use multiple tables when either of the following occurs:
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, TopLink assumes that the primary key of the first, or primary, table is included in the additional tables, thereby joining the tables. TopLink also supports custom methods for joining tables. If the primary key field names of the multiple tables do not match, a foreign key can be used to join the tables. The foreign key can either be from the primary table to the secondary table, or from the secondary table to the primary table, or between two of the secondary tables (see "Using TopLink Workbench").
For complex multitable situations, a more complex join expression may be required. These include requiring the join to also check a type code, or using an outer-join. TopLink provides support for a multiple-table-join-expression for these cases (see "Using Java").
Use the Multitable Info tab to define multiple tables for a descriptor in TopLink Workbench.
To associate multiple tables with a descriptor, use this procedure.
In the Navigator, select a descriptor.
If the Multitable Info advanced property is not visible for the descriptor, right-click the descriptor and choose Select Advanced Properties > Multitable Info from the context menu or from the Selected menu.
Use the following information to enter data in each field of the tab:
Field | Description |
---|---|
Primary Table | The primary table for this descriptor. This field is for display only. |
Additional Tables | Use Add and Remove to add or remove additional tables. |
Association to Primary Table | Specify how each Additional Table is associated to the Primary Table:
|
Associating Tables With References
When associating a table using Reference, additional options appear. You must choose a reference that relates the correct fields in the primary table to the primary keys in the selected table.
Figure 29-6 Multitable Info Tab, Associated by Reference
Choose a Table Reference that defines how the primary keys of the primary table relate to the primary keys of the selected table. Click Add to add a primary key association.
Using Java, configure a descriptor with multitable information using the following ClassDescriptor
methods:
addTable
Name
addMultipleTableForeignKeyFieldName
To specify a complex multiple-table-join-expression, create a descriptor amendment method (see "Configuring Amendment Methods") and add the join expression using DescriptorQueryManager
method setMultipleTableJoinExpression
. For more information, see "Appending Additional Join Expressions".