Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
You cannot create an object-relational descriptor using TopLink Workbench: you must use Java code. For more information on creating descriptors in Java code, see the Oracle TopLink API Reference.
For more information, see "Object-Relational Descriptors".
Use the ObjectRelationalDescriptor
class to define an object-relational descriptor. This class extends RelationalDescriptor
to add the following methods:
setStructureName
: call this method to set the name of the object-relational structure that represents the object class in the data source.
addFieldOrdering
: call this method repeatedly to define the order in which object attributes are persisted to the data source. This defines a field index that TopLink uses if your object-relational data source driver uses JDBC indexed arrays.
Example 27-2 shows an Employee
object that is mapped to an Oracle Database using its object-relational features.
Example 27-2 Employee Class
public class Employee { Long id; String firstName; String lastName; ... }
Example 27-3 shows the object-relational database type (Employee_t
) created to model the Employee
object within the database. Such an object-relational database type is also known as a structure. This example also shows how to create and populate a database table (called department
) that stores instances of the Employee_t
audio tape.
Example 27-3 Employee Object-Relational Data Model
CREATE TYPE EMPLOYEE_T AS OBJECT( ID NUMBER(10), F_NAME VARCHAR2(100), L_NAME VARCHAR2(100),) NOT FINAL; CREATE TABLE EMPLOYEES OF TYPE EMPLOYEE_T;
Example 27-4 shows how to code an object-relational descriptor in Java to describe the object-relational database type Employee_t
.
Example 27-4 Creating an Object-Relational Descriptor in Java
import oracle.toplink.objectrelational.*; ObjectRelationalDescriptor descriptor = new ObjectRelationalDescriptor(); descriptor.setJavaClass(Employee.class); descriptor.setTableName("EMPLOYEES"); descriptor.setStructureName("EMPLOYEE_T"); descriptor.setPrimaryKeyFieldName("ID"); descriptor.addFieldOrdering("ID"); descriptor.addFieldOrdering("F_NAME"); descriptor.addFieldOrdering("L_NAME"); descriptor.addDirectMapping("id", "OBJECT_ID"); descriptor.addDirectMapping("firstName", "F_NAME"); descriptor.addDirectMapping("lastName", "L_NAME");
For more information on configuring object-relational descriptors, see "Configuring an Object-Relational Descriptor".
For more information on the object-relational mappings that TopLink supports, see Chapter 49, "Understanding Object-Relational Mappings".