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 Multitable Information

Descriptors can use multiple tables in mappings. Use multiple tables when either of the following occurs:

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").

Using TopLink Workbench

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.

  1. 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.

  2. Click the Multitable Info tab.

    Figure 29-5 Multitable Info Tab

    Description of Figure 29-5 follows
    Description of "Figure 29-5 Multitable Info Tab"

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:
  • Primary Keys Have Same Names–when associating tables by identically named primary keys, TopLink requires no additional configuration.

  • Reference–when associating an additional table to the primary table with a Reference (that is, a foreign key), you can specify the Table Reference, as well as the Source and Target fields. Continue with "Associating Tables With References".


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

Description of Figure 29-6 follows
Description of "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

Using Java, configure a descriptor with multitable information using the following ClassDescriptor methods:

  • addTableName

  • 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".