Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Configuring an Object-Relational Data Type Mapping (ELUG)
Contents
For information on how to create EclipseLink mappings, see Creating a Mapping.
This table 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.
For more information, see the following:
Configuring Common Object-Relational Data Type Mapping Options
Thist able 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 Object-Relational Data Type Mapping Types), as shown in the following table.
Option to Configure | Workbench |
Java |
---|---|---|
Configuring Reference Class
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.
This table summarizes which object-relational data type mappings support this option.
Mapping | Using the Workbench | Using Java |
---|---|---|
How to Configure Reference Class Using Java
Use org.eclipse.persistence.mappings.ForeignReferenceMapping method setReferenceClass to specify the target class of the attribute being mapped.
Tihs example shows how to use this method with a ReferenceMapping that maps the manager attribute of the Employee class.
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 EclipseLink API Reference.
Configuring Attribute Name
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 Configuring Reference Class).
This table summarizes which object-relational data type mappings support this option.
Mapping | Using the Workbench | Using Java |
---|---|---|
How to Configure Attribute Name Using Java
Use org.eclipse.persistence.mappings.DatabaseMapping method setAttributeName to specify the name of the attribute being mapped.
This table shows how to use this method with a ReferenceMapping that maps the manager attribute of the Employee class.
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 EclipseLink API Reference.
Configuring Field Name
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.
This table summarizes which object-relational data type mappings support this option.
Mapping | Using the Workbench | Using Java |
---|---|---|
How to Configure Field Name Using Java
Use the object-relational data type mapping method setFieldName to specify the database field to which the attribute is mapped.
This example shows how to use this method with an ObjectArrayMapping that maps the Employee class attribute phone to database field name PHONE_NUMBER.
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 EclipseLink API Reference.
Configuring Structure Name
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.
This table summarizes which object-relational data type mappings support this option.
Mapping | Using the Workbench | Using Java |
---|---|---|
How to Configure Structure Name Using Java
Use the object-relational data type mapping method setStructureName to specify the structure of the attribute being mapped.
This example 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.
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 EclipseLink API Reference.