5.3. Managed Inverses
Prev | Chapter 5. Persistent Classes | Next

## 5.3. Managed Inverses

Bidirectional relations are an essential part of data modeling. Java does not provide any native facilities to ensure that both sides of a bidirectional relation remain consistent. Whenever you set one side of the relation, you must manually set the other side as well.

By default, Kodo behaves the same way. Kodo does not automatically propogate changes from one field in bidirectional relation to the other field. This is in keeping with JDO's philosophy of transparency, and also provides higher performance, as Kodo does not need to analyze your object graph to correct inconsistent relations.

If convenience is more important to you than strict transparency, however, you can enable inverse relation management in Kodo. Set the `kodo.InverseManager` plugin property to `true` for standard management. Under this setting, Kodo detects changes to either side of a bidirectional relation, and automatically sets the other side appropriately on flush.

Example 5.6. Enabling Managed Inverses

    kodo.InverseManager: true

The inverse manager has options to log a warning or throw an exception when it detects an inconsistent bidirectional relation, rather than correcting it. To use these modes, set the manager's `Action` property to `warn` or `exception`, respectively.

By default, Kodo excludes large result set fields from management. You can force large result set fields to be included with the `ManageLRS` plugin property, as in the example below.

Example 5.7. Log Inconsistencies, Including LRS Fields

    kodo.InverseManager: true(Action=warn, ManageLRS=true)

Use the `inverse-owner` or `inverse-logical` metadata extensions to name the inverse of a bidirectional relation. The former extension implies that the fields share the same datasturcture in the database, while the latter does not. See Section 6.2.1.1, “inverse-owner” and Section 6.2.1.2, “inverse-logical” for details.

Prev | Up | Next
5.2. Object Identity | Home | 5.4. Mutable Second Class Object Fields