Skip Headers

# Configuring Bidirectional Relationship

Previous

Next

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. For more information, see the following:

- Directionality

- Maintaining Bidirectional Relationships

- Indirection

Table: Mapping Support for Mutable Mappings summarizes which mappings support this option.

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