Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Creating an Object-Relational Data Type Descriptor (ELUG)"
m (→How to Create an Object-Relational Data Type Descriptor Using Java) |
m (227400) |
||
Line 28: | Line 28: | ||
<span id="Example 30-1"></span> | <span id="Example 30-1"></span> | ||
''''' Employee Class''''' | ''''' Employee Class''''' | ||
+ | <source lang="java"> | ||
public class Employee { | public class Employee { | ||
Long id; | Long id; | ||
Line 35: | Line 36: | ||
... | ... | ||
} | } | ||
− | + | </source> | |
This example shows the object-relational data type database type (<tt>Employee_t</tt>) created to model the <tt>Employee</tt> 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 <tt>department</tt>) that stores instances of the <tt>Employee_t</tt> audio tape. | This example shows the object-relational data type database type (<tt>Employee_t</tt>) created to model the <tt>Employee</tt> 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 <tt>department</tt>) that stores instances of the <tt>Employee_t</tt> audio tape. | ||
Line 41: | Line 42: | ||
<span id="Example 30-2"></span> | <span id="Example 30-2"></span> | ||
''''' Employee Object-Relational Data Type Data Model''''' | ''''' Employee Object-Relational Data Type Data Model''''' | ||
+ | <source lang="sql"> | ||
CREATE TYPE EMPLOYEE_T AS OBJECT(ID NUMBER(10), | CREATE TYPE EMPLOYEE_T AS OBJECT(ID NUMBER(10), | ||
F_NAME VARCHAR2(100), | F_NAME VARCHAR2(100), | ||
L_NAME VARCHAR2(100),) NOT FINAL; | L_NAME VARCHAR2(100),) NOT FINAL; | ||
CREATE TABLE EMPLOYEES OF EMPLOYEE_T; | CREATE TABLE EMPLOYEES OF EMPLOYEE_T; | ||
+ | </source> | ||
This example shows how to code an object-relational data type descriptor in Java to describe the object-relational data type database type <tt>Employee_t</tt>. | This example shows how to code an object-relational data type descriptor in Java to describe the object-relational data type database type <tt>Employee_t</tt>. | ||
Line 51: | Line 54: | ||
<span id="Example 30-3"></span> | <span id="Example 30-3"></span> | ||
''''' Creating an Object-Relational Data Type Descriptor in Java''''' | ''''' Creating an Object-Relational Data Type Descriptor in Java''''' | ||
+ | <source lang="java"> | ||
import org.eclipse.persistence.mappings.structures.*; | import org.eclipse.persistence.mappings.structures.*; | ||
... | ... | ||
Line 64: | Line 68: | ||
descriptor.addDirectMapping("firstName", "F_NAME"); | descriptor.addDirectMapping("firstName", "F_NAME"); | ||
descriptor.addDirectMapping("lastName", "L_NAME"); | descriptor.addDirectMapping("lastName", "L_NAME"); | ||
+ | </source> | ||
For more information on configuring object-relational data type descriptors, see [[Configuring%20an%20Object-Relational%20Data%20Type%20Descriptor%20(ELUG)|Configuring an Object-Relational Data Type Descriptor]]. | For more information on configuring object-relational data type descriptors, see [[Configuring%20an%20Object-Relational%20Data%20Type%20Descriptor%20(ELUG)|Configuring an Object-Relational Data Type Descriptor]]. |
Latest revision as of 09:44, 20 May 2009
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.