Skip Headers

# Indirection

Previous

Next

By default, when TopLink retrieves a persistent object, it retrieves all of the dependent objects to which it refers. When you configure indirection (also known as lazy reading, lazy loading, and just-in-time reading) for an attribute mapped with a relationship mapping, TopLink uses an indirection object as a place holder for the referenced object: TopLink defers reading the dependent object until you access that specific attribute. This can result in a significant performance improvement, especially if the application is interested only in the contents of the retrieved object, rather than the objects to which it is related.

Oracle strongly recommends using indirection for all relationship mappings. Not only does this lets you optimize data source access, but it also allows TopLink to optimize the unit of work processing, cache access, and concurrency.

Note: The use of indirection is especially important for providing a proper maintenance of bidirectional relationships (see "Maintaining Bidirectional Relationships"). In this case, you must use indirection. If you are operating with collections, you must use transparent indirection (see "Transparent Indirect Container Indirection").

Figure: TopLink Indirection shows an indirection example. Without indirection, reading the `Order` object also reads the dependent collection of `LineItem` objects. With indirection, reading the `Order` object does not read the dependent collection of `LineItem` objects: the `lineItems` attribute refers to an indirection object. You can access other attributes (such as `customerId`), but TopLink reads the dependent `LineItem` objects only if and when you access the `lineItems` attribute.

TopLink Indirection

Description of "TopLink Indirection"

TopLink supports the following types of indirection:

- Value Holder Indirection

- Transparent Indirect Container Indirection

- Proxy Indirection

When using indirection with EJB, the version of EJB and application server you use affects how indirection is configured and what types of indirection are applicable (see "Indirection and EJB").

When using indirection with an object that your application serializes, you must consider the effect of any untriggered indirection objects at deserialization time (see "Indirection, Serialization, and Detachment").

For information on configuring indirection, see "Configuring Indirection".