Skip Headers

# Configuring ValueHolder Indirection

Previous

Next

Instances of `oracle.toplink.mappings.ForeignReferenceMapping` and `oracle.toplink.mappings.foundation.AbstractTransformationMapping` provide the `useBasicIndirection` method to configure a mapping to an attribute that you code with an `oracle.toplink.indirection.ValueHolderInterface` between it and the real object.

If the attribute is of a `Collection` type (such as a `Vector`), then you can either use an `IndirectContainer` (see "Configuring IndirectContainer Indirection") or define the `ValueHolder` in the constructor as follows:

`addresses = new ValueHolder(new Vector());`

Example: Class Using ValueHolder Indirection illustrates the `Employee` class using `ValueHolder` indirection. The class definition conceals the use of ValueHolder within the existing getter and setter methods.

Class Using ValueHolder Indirection

    public class Employee {

        protected ValueHolderInterface address;

        // Initialize ValueHolders in constructor
        public Employee() {
            address = new ValueHolder();
        }

        public Address getAddress() {
            return (Address) this.addressHolder.getValue();
        }

        public void setAddress(Address address) {
            this.addressHolder.setValue(address);
        }
    }

Example: Mapping Using ValueHolder Indirection shows how to configure a one-to-one mapping to the `address` attribute.

Mapping Using ValueHolder Indirection

    OneToOneMapping mapping = new OneToOneMapping();
    mapping.useBasicIndirection();
    mapping.setReferenceClass(Employee.class);
    mapping.setAttributeName("address");

The application uses `Employee` methods `getAddress` and `setAddress` to access the `Address` object. Because basic indirection is enabled, TopLink expects the persistent fields to be of type `ValueHolderInterface`.