Skip Headers

# Value Holder Indirection

Previous

Next

Persistent classes that use indirection must replace relationship attributes with value holder attributes. A value holder is an instance of a class that implements the `ValueHolderInterface` interface, such as `ValueHolder`. This object stores the information necessary to retrieve the object it is replacing from the database. If the application does not access the value holder, the replaced object is never read from the database.

To obtain the object that the value holder replaces, use the `getValue` and `setValue` methods of the `ValueHolderInterface`. A convenient way of using these methods is to hide the `getValue` and `setValue` methods of the `ValueHolderInterface` inside `get` and `set` methods, as shown in the following illustrations.

Figure: Address Object Not Read shows the `Employee` object being read from the database. The `Address` object is not read and will not be created unless it is accessed.

Address Object Not Read

Description of "Address Object Not Read"

The first time the address is accessed, as in Figure: Initial Request, the `ValueHolder` reads and returns the `Address` object.

Initial Request

Description of "Initial Request"

Subsequent requests for the address do not access the database, as shown in Figure: Subsequent Requests.

Subsequent Requests

Description of "Subsequent Requests"

If you are using method access ("Configuring Method Accessing"), the get and set methods specified in the mapping must access the instance of `ValueHolderInterface`, rather than the object referenced by the value holder. The application should not use these getter and setter, but use the getter and setter that hide the usage of value holders. For more information, see "Configuring ValueHolder Indirection With Method Accessing".

See Also

  Configuring Indirection
  Transparent Indirect Container Indirection