Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
In an object-relational data-model, structures reference each other through refs—not through foreign keys (as in a traditional data-model). Refs are based on the target structure's ObjectID
.
OracleAS TopLink supports refs through the ReferenceMapping
class. They represent an object reference in Java, similar to a OneToOneMapping
. However, the reference mapping does not require foreign key information.
Reference mappings are instances of the ReferenceMapping
class. You must associate this mapping to an attribute in the source class. OracleAS TopLink requires the following elements for a reference mapping:
Attribute being mapped – Set by sending the setAttributeName( )
message.
Field being mapped – Set by sending the setFieldName( )
message.
Target class – Set by sending the setReferenceClass( )
message.
Use the optional setGetMethodName( )
and setSetMethodName( )
messages to access the attribute through user-defined methods rather than directly. See "Specifying Direct Access and Method Access" on page 4-71 for more information.
Table 7–4 summarizes all reference mapping properties.
Example 7-4 Reference Mapping
The following code example illustrates creating a reference mapping for the Employee
source class and registering it with the descriptor.
// Create a new mapping and register it with the source descriptor. ReferenceMapping refrenceMapping = new ReferenceMapping(); referenceMapping.setAttributeName(ÒmanagerÓ); referenceMapping.setReferenceClass(Employee.class); referenceMapping.setFieldName("MANAGER"); descriptor.addMapping(refrenceMapping);
The following table summarizes all reference mapping properties. In the Method Names column, arguments are bold, methods are not.
Table 7-4 Properties for ReferenceMapping Methods
Property | Default | Method Names |
---|---|---|
* Required property |
|
|
Attribute to be mapped * | not applicable | setAttributeName (String name)
|
Set parent class * | not applicable | setReferenceClass (Class aClass)
|
Field to be mapped * | not applicable | setFieldName (String fieldName)
|
Method access | direct access | setGetMethodName (String name)
|
Indirection | use indirection | useBasicIndirection ()
|
Privately owned relationship | independent | independentRelationship ()
|
Read only | read / write | readWrite ()
|