Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Working with Variable One-to-One Mappings

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:

Specifying Class Indicator

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).

Figure 6-14 Class indicator Field

Description of clinfig.gif follows
Description of the illustration clinfig.gif

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.

Specifying Unique Primary Key

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.

Figure 6-15 Unique primary key

Description of uniquepk.gif follows
Description of the illustration uniquepk.gif

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.

Creating Variable One-to-One Mappings

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:

  1. In the Navigator pane, select the interface descriptor that will be referenced.

  2. 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.

Figure 6-16 Implementors Tab

Description of 11tarint.gif follows
Description of the illustration 11tarint.gif

  1. Variable One-to-One Mapping button.
    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.

  2. Select the General tab.

Figure 6-17 Variable One-to-One Mapping General Properties

Description of 11refint.gif follows
Description of the illustration 11refint.gif

  1. Use the Reference Descriptor drop-down list to choose a reference descriptor. The OracleAS TopLink Mapping Workbench displays only interface descriptors.

  2. Enter any other required information on the General tab (see "Working with Common Mapping Properties" on page 4-70).

  3. Select the Query Key Associations tab.

Figure 6-18 Variable One-to-One Mapping Query Key Associations Properties

Description of qkassoc.gif follows
Description of the illustration qkassoc.gif

  1. Specify fields in the source descriptor's tables to use for common query keys.

  2. Select the Class Indicator Info tab.

Figure 6-19 Variable One-to-One Mapping Class Indicator Info Tab

Description of clinfld.gif follows
Description of the illustration clinfld.gif

  1. 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.