Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
Variable class relationships are similar to polymorphic relationships except that in this case the target classes are not related through inheritance (and thus not good candidates for an abstract table), but through an interface.
To define variable class relationships in OracleAS TopLink Mapping Workbench, use the variable one-to-one mapping selection, but choose the interface as the reference class. This makes the mapping a variable one-to-one. When defining mappings in Java code, use the VariableOneToOneMapping
class.
OracleAS TopLink supports variable relationships only in one-to-one mappings. It handles this relationship in two ways:
Through the class indicator field
Through unique primary key values among target classes implementing the interface
A source table has an indicator column that specifies the target table through the class indicator field, as show in Figure 6-14. The EMPLOYEE table has a TYPE column that indicates the target for the row (either PHONE or EMAIL).
The principles of defining such a variable class relationship are similar to defining a normal one-to-one relationship, except:
The reference class is a Java interface, not a Java class. However, the method to set the interface is identical.
You must specify a type indicator field.
You specify the class indicator values on the mapping so that mapping can determine the class of object to create.
You must specify the foreign key names and the respective abstract query keys from the target interface descriptor.
As Figure 6-15 illustrates, the value of the foreign key in the source table mapped to the primary key of the target table is unique. No primary key values among the target tables are the same, so primary key values are not unique just in the table, but also among the tables.
Because there is no indicator stored in the source table, OracleAS TopLink cannot determine to which target table the foreign key value is mapped. Therefore, OracleAS TopLink reads through all the target tables until it finds an entry in one of the target tables. This is an inefficient way of setting up a relation model, because reading is expensive. The class indicator is much more efficient and it reduces the number of reads performed on the tables to get the data. In the class indicator method, OracleAS TopLink knows exactly which target table to look into for the data.
The principles of defining such a variable class relationship are similar to defining class indicator variable one-to-one relationships, except:
A type indicator field is not specified.
The class indicator values are not specified.
The type indicator field and its values are not needed, because OracleAS TopLink goes through all the target tables until data is finally found.
Use this procedure to create a variable one-to-one mapping. You must configure the target descriptor before defining the mapping.
To create a variable one-to-one mapping:
In the Navigator pane, select the interface descriptor that will be referenced.
On the Implementors tab, choose all descriptors that implement this interface and share a common query key. You may need to create query keys for some or all of these descriptors.
Description of the illustration v11mapbt.gif
In the Navigator pane, select the attribute to be mapped as a variable one-to-one mapping and click the Variable One-to-One Mapping button on the mapping toolbar.
Figure 6-17 Variable One-to-One Mapping General Properties
Use the Reference Descriptor drop-down list to choose a reference descriptor. The OracleAS TopLink Mapping Workbench displays only interface descriptors.
Enter any other required information on the General tab (see "Working with Common Mapping Properties" on page 4-70).
Figure 6-18 Variable One-to-One Mapping Query Key Associations Properties
Specify fields in the source descriptor's tables to use for common query keys.
Figure 6-19 Variable One-to-One Mapping Class Indicator Info Tab
Use this table to enter data in each field.
Field | Description |
---|---|
Class Indicator Field | Use the drop-down list to choose a field to use as a class indicator. To use unique primary keys (no class indicator values), choose <none selected>. |
Indicator Type | Use the drop-down list to choose the Java type for the Class Indicator Field. |
Class information: |
|
Include | Specify to use this class for the mapping. |
Class | Name of the class. This field is for display only. |
Indicator Value | Value used by this class. |
Note: If the class does not appear in the Class Information table, you must add the class in the interface descriptor. See "Implementing an Interface" on page 4-48 for more information. |