Attributes using indirection must conform to the ValueHolderInterface. You can change your attribute types in the Class Editor without re-importing your Java classes. Ensure that you change the attribute types in your Java code as well. Attributes typed incorrectly will be marked as deficient.
In addition to changing the attribute's type, you may also need to change its accessor methods. If you use method access, TopLink requires accessors to the indirection object itself, so your get method returns an instance that conforms to ValueHolderInterface, and your set method accepts one argument that conforms to the same. If the instance variable returns a Vector instead of an object, then the value holder should be defined in the constructor as follows:
In any case, the application uses the getAddress() and setAddress() methods to access the Address object. With indirection, TopLink uses the getAddressHolder() and setAddressHolder() methods when saving and retrieving instances to and from the database.
Refer to the book OracleAS TopLink Application Developer's Guide for details.
Example 5-2 Indirection
The following code illustrates the Employee class using indirection with method access for a one-to-one mapping to Address.
The class definition is modified so that the address attribute of Employee is a ValueHolderInterface instead of an Address, and appropriate get and set methods are supplied.
// Initialize ValueHolders in Employee Constructor
public Employee() {
address = new ValueHolder();
}
protected ValueHolderInterface address;
// 'Get' and 'Set' accessor methods registered with the mapping and used by OracleAS TopLink.
public ValueHolderInterface getAddressHolder() {
return address;
}
public void setAddressHolder(ValueHolderInterface holder) {
address = holder;
}
// 'Get' and 'Set' accessor methods used by the application to access the attribute.
public Address getAddress() {
return (Address) address.getValue();
}
public void setAddress(Address theAddress) {
address.setValue(theAddress);
}
Copyright © 1997, 2004, Oracle. All rights reserved.