Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring Bidirectional Relationship

If a mapping has a bidirectional relationship in which the two classes in the relationship reference each other with one-to-one mappings, then set up the foreign key information as follows:

- One mapping must call the `setForeignKeyFieldName` method.

- The other must call the `setTargetForeignKeyFieldName` method.

It is also possible to set up composite foreign key information by calling the `addForeignKeyFieldName` and `addTargetForeignKeyFieldName` methods. Because TopLink enables indirection by default, the attribute must be a `ValueHolderInterface`.

Note: When your application does not use a cache, enable indirection for at least one object in a bidirectional relationship. In rare cases, disabling indirection on both objects in the bidirectional relationship can lead to infinite loops.

Table 35-18 summarizes which mappings support this option.

Table 35-19 Mapping Support for Mutable Mappings

Mapping | Using TopLink Workbench | Using Java
--- | --- | ---
Relational Mappings |  |
One-to-One Mapping |  |
One-to-Many Mapping |  |
Many-to-Many Mapping |  |
EIS Mappings |  |
EIS One-to-One Mapping |  |
EIS One-to-Many Mapping |  |

## Using TopLink Workbench

To maintain a bidirectional relationship for a mapping, use this procedure:

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

2. Click the General tab. The General tab appears.

   Figure 35-18 General tab, Maintains Bidirectional Relationship option

   Description of "Figure 35-18 General tab, Maintains Bidirectional Relationship option"

Use this table to enter data in the following fields on the tab:

Field | Description
--- | ---
Maintains Bidirectional Relationship | Specify if TopLink should maintain the bidirectional link for this relational mapping.
Relationship Partner | Select the relationship partner (from the list of mapped attributes of the Reference Descriptor) for this bidirectional relationship.