Oracle Fusion Middleware Developer's Guide for Oracle TopLink 11g Release 1 (11.1.1) Part Number B32441-03 |
|
|
View PDF |
This chapter describes how to configure an object-relational data type mapping.
This chapter includes the following sections:
Introduction to Object-Relational Data Type Mapping Configuration
Configuring Common Object-Relational Data Type Mapping Options
For information on how to configure TopLink mappings options common to two or more mapping types, see Chapter 121, "Configuring a Mapping".
For information on how to create TopLink mappings, see Chapter 120, "Creating a Mapping".
Table 41-1 lists the types of object-relational data type mappings that you can configure and provides a cross-reference to the type-specific chapter that lists the configurable options supported by that type.
Table 41-1 Configuring Object-Relational Data Type Mappings
If you are creating... | See Also... |
---|---|
Object-relational data type structure mapping (see Section 40.1.1, "Object-Relational Data Type Structure Mapping") |
Chapter 42, "Configuring an Object-Relational Data Type Structure Mapping" |
Object-relational data type reference mapping (see Section 40.1.2, "Object-Relational Data Type Reference Mapping") |
Chapter 43, "Configuring an Object-Relational Data Type Reference Mapping" |
Object-relational data type array mapping (see Section 40.1.3, "Object-Relational Data Type Array Mapping") |
Chapter 44, "Configuring an Object-Relational Data Type Array Mapping" |
Object-relational data type object array mapping (see Section 40.1.4, "Object-Relational Data Type Object Array Mapping") |
Chapter 45, "Configuring an Object-Relational Data Type Object Array Mapping" |
Object-relational data type nested table mapping (see Section 40.1.5, "Object-Relational Data Type Nested Table Mapping") |
Chapter 46, "Configuring an Object-Relational Data Type Nested Table Mapping" |
For more information, see the following:
Table 41-2 lists the configurable options shared by two or more object-relational data type mapping types. In addition to the configurable options described here, you must also configure the options described for the specific object-relational data type mapping types (see Section 40.1, "Object-Relational Data Type Mapping Types"), as shown in Table 41-1.
Table 41-2 Common Options for Object-Relational Data Type Mappings
Option to Configure | Oracle JDeveloper |
TopLink Workbench |
Java |
---|---|---|---|
Reference class (see Section 41.3, "Configuring Reference Class") |
![]() |
![]() |
![]() |
Attribute name (see Section 41.4, "Configuring Attribute Name") |
![]() |
![]() |
![]() |
Field name (see Section 41.5, "Configuring Field Name") |
![]() |
![]() |
![]() |
Structure name (see Section 41.6, "Configuring Structure Name") |
![]() |
![]() |
![]() |
Read-only (see Section 121.2, "Configuring Read-Only Mappings") |
![]() |
![]() |
![]() |
Method or direct field access (see Section 121.6, "Configuring Method or Direct Field Accessing at the Mapping Level") |
![]() |
![]() |
![]() |
Indirection (lazy loading) (see Section 121.3, "Configuring Indirection (Lazy Loading)") |
![]() |
![]() |
![]() |
Container policy (see Section 121.14, "Configuring Container Policy") |
![]() |
![]() |
![]() |
When mapping an attribute that involves a relationship to another class, you must specify the reference class–the Java class to which the mapped attribute refers.
Table 41-3 summarizes which object-relational data type mappings support this option.
Table 41-3 Mapping Support for Reference Class
Mapping | How to Use Oracle JDeveloper | How to Use TopLink Workbench | How to Configure Reference Class Using Java |
---|---|---|---|
Object-relational data type structure mapping (see Section 40.1.1, "Object-Relational Data Type Structure Mapping") |
|
|
|
Object-relational data type reference mapping (see Section 40.1.2, "Object-Relational Data Type Reference Mapping") |
|
|
|
Object-relational data type array mapping (see Section 40.1.3, "Object-Relational Data Type Array Mapping") |
|
|
|
Object-relational data type object array mapping (see Section 40.1.4, "Object-Relational Data Type Object Array Mapping") |
|
|
|
Object-relational data type nested table mapping (see Section 40.1.5, "Object-Relational Data Type Nested Table Mapping") |
|
|
|
Use oracle.toplink.mappings.ForeignReferenceMapping
method setReferenceClass
to specify the target class of the attribute being mapped.
Example 41-1 shows how to use this method with a ReferenceMapping
that maps the manager
attribute of the Employee
class.
Example 41-1 Configuring Reference Class in Java
public void customize(ClassDescriptor descriptor) { ReferenceMapping managerMapping = new ReferenceMapping(); managerMapping.setReferenceClass("Employee.class"); // set reference class managerMapping.setAttributeName("manager"); // add this mapping to descriptor descriptor.addMapping(managerMapping); }
For more information, see the Oracle Fusion Middleware Java API Reference for Oracle TopLink.
All object-relational data type mappings map an attribute in a Java object to field in the database. The attribute name is the name of the attribute being mapped. The name is as specified in the reference class (see Section 41.3, "Configuring Reference Class").
Table 41-4 summarizes which object-relational data type mappings support this option.
Table 41-4 Mapping Support for Attribute Name
Mapping | How to Use Oracle JDeveloper | How to Use TopLink Workbench | How to Configure Attribute Name Using Java |
---|---|---|---|
Object-relational data type structure mapping (see Section 40.1.1, "Object-Relational Data Type Structure Mapping") |
|
![]() |
|
Object-relational data type reference mapping (see Section 40.1.2, "Object-Relational Data Type Reference Mapping") |
|
![]() |
|
Object-relational data type array mapping (see Section 40.1.3, "Object-Relational Data Type Array Mapping") |
|
![]() |
|
Object-relational data type object array mapping (see Section 40.1.4, "Object-Relational Data Type Object Array Mapping") |
|
![]() |
|
Object-relational data type nested table mapping (see Section 40.1.5, "Object-Relational Data Type Nested Table Mapping") |
|
![]() |
|
Use oracle.toplink.mappings.DatabaseMapping
method setAttributeName
to specify the name of the attribute being mapped.
Example 41-2 shows how to use this method with a ReferenceMapping
that maps the manager
attribute of the Employee
class.
Example 41-2 Configuring Attribute Name in Java
public void customize(ClassDescriptor descriptor) {
ReferenceMapping managerMapping = new new ReferenceMapping();
managerMapping.setReferenceClass("Employee.class");
managerMapping.setAttributeName("manager"); // set attribute name
// add this mapping to descriptor
descriptor.addMapping (managerMapping);
}
For more information, see the Oracle Fusion Middleware Java API Reference for Oracle TopLink.
All object-relational data type mappings require the name of database field to which their specified attribute is mapped. This field name can be the column name of a database table or the name of a field in an object type created on the database.
Table 41-5 summarizes which object-relational data type mappings support this option.
Table 41-5 Mapping Support for Field Name
Mapping | How to Use Oracle JDeveloper | How to Use TopLink Workbench | How to Configure Field Name Using Java |
---|---|---|---|
Object-relational data type structure mapping (see Section 40.1.1, "Object-Relational Data Type Structure Mapping") |
|
|
|
Object-relational data type reference mapping (see Section 40.1.2, "Object-Relational Data Type Reference Mapping") |
|
|
|
Object-relational data type array mapping (see Section 40.1.3, "Object-Relational Data Type Array Mapping") |
|
|
|
Object-relational data type object array mapping (see Section 40.1.4, "Object-Relational Data Type Object Array Mapping") |
|
|
|
Object-relational data type nested table mapping (see Section 40.1.5, "Object-Relational Data Type Nested Table Mapping") |
|
|
|
Use the object-relational data type mapping method setFieldName
to specify the database field to which the attribute is mapped.
Example 41-3 shows how to use this method with an ObjectArrayMapping
that maps the Employee
class attribute phone
to database field name PHONE_NUMBER
.
Example 41-3 Configuring Field Name in Java
public void customize(ClassDescriptor descriptor) { ObjectArrayMapping phonesMapping = new ObjectArrayMapping(); phonesMapping.setReferenceClass("Employee.class"); phonesMapping.setAttributeName("phone"); phonesMapping.setFieldName("PHONE_NUMBER"); // set field name // add this mapping to descriptor descriptor.addMapping (phonesMapping); }
For more information, see the Oracle Fusion Middleware Java API Reference for Oracle TopLink.
Certain object-relational data type mappings require the specification of the data type or structure name of the field being mapped. The structure name is the name of the array or table type that defines the field.
Table 41-6 summarizes which object-relational data type mappings support this option.
Table 41-6 Mapping Support for Structure Name
Mapping | How to Use Oracle JDeveloper | How to Use TopLink Workbench | How to Configure Structure Name Using Java |
---|---|---|---|
Object-relational data type structure mapping (see Section 40.1.1, "Object-Relational Data Type Structure Mapping") |
|
|
|
Object-relational data type reference mapping (see Section 40.1.2, "Object-Relational Data Type Reference Mapping") |
|
|
|
Object-relational data type array mapping (see Section 40.1.3, "Object-Relational Data Type Array Mapping") |
|
|
|
Object-relational data type object array mapping (see Section 40.1.4, "Object-Relational Data Type Object Array Mapping") |
|
|
|
Object-relational data type nested table mapping (see Section 40.1.5, "Object-Relational Data Type Nested Table Mapping") |
|
|
|
Use the object-relational data type mapping method setStructureName
to specify the structure of the attribute being mapped.
Example 41-4 shows how to use this method with an ObjectArrayMapping
that maps the Employee
class attribute phones
to database field name PHONE_NUMBERS
of type PHONE_ARRAY_TYPE
.
Example 41-4 Configuring Structure Name in Java
public void customize(ClassDescriptor descriptor) { ObjectArrayMapping phonesMapping = new ObjectArrayMapping(); phonesMapping.setReferenceClass("Employee.class"); phonesMapping.setAttributeName("phones"); phonesMapping.setFieldName("PHONE_NUMBERS"); phonesMapping.setStructureName("PHONE_ARRAY_TYPE"); // set structure name // add this mapping to descriptor descriptor.addMapping (phonesMapping); }
For more information, see the Oracle Fusion Middleware Java API Reference for Oracle TopLink.