Creating an Object-Relational Data Type Descriptor (ELUG)
From Eclipsepedia
Contents |
After you create a descriptor, you must configure its various options (see Configuring a Descriptor) and use it to define mappings.
For complete information on the various types of mapping that EclipseLink supports, see Introduction to Mappings and Creating a Mapping.
For complete information on the various types of descriptor that EclipseLink supports, see Descriptor Types.
For more information, see Introduction to Object-Relational Data Type Descriptors.
Creating an Object-Relational Data Type Descriptor
You cannot create an object-relational data type descriptor using the Workbench: you must use Java code. For more information on creating descriptors in Java code, see the EclipseLink API Reference.
For more information, see Object-Relational Data Type Descriptors.
How to Create an Object-Relational Data Type Descriptor Using Java
Use the ObjectRelationalDescriptor class to define an object-relational data type descriptor. This class extends RelationalDescriptor to add the following methods:
- setStructureName: call this method to set the name of the object-relational data type 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 EclipseLink uses if your object-relational data type data source driver uses JDBC indexed arrays.
This example shows an Employee object that is mapped to an Oracle Database using its object-relational data type features.
Employee Class
public class Employee {
Long id;
String firstName;
String lastName;
...
}
This example shows the object-relational data type database type (Employee_t) created to model the Employee object within the database. Such an object-relational data type 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.
Employee Object-Relational Data Type 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 EMPLOYEE_T;
This example shows how to code an object-relational data type descriptor in Java to describe the object-relational data type database type Employee_t.
Creating an Object-Relational Data Type Descriptor in Java
import org.eclipse.persistence.mappings.structures.*;
...
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 data type descriptors, see Configuring an Object-Relational Data Type Descriptor.
For more information on the object-relational data type mappings that EclipseLink supports, see Introduction to Object-Relational Data Type Mappings.

