Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "Configuring a Relational Direct Collection Mapping (ELUG)"

m
m (How to Configure Direct Value Field Using Java)
 
(4 intermediate revisions by one other user not shown)
Line 99: Line 99:
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
 
|}
 
|}
 
  
 
This example shows how to create a direct collection mapping and add it to a descriptor using Java code.
 
This example shows how to create a direct collection mapping and add it to a descriptor using Java code.
Line 121: Line 120:
 
* [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Direct Collection Mapping|Direct Collection Mapping]]
 
* [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Direct Collection Mapping|Direct Collection Mapping]]
 
* [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring a Relational Mapping]]
 
* [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring a Relational Mapping]]
* [[Creating%20and%20Configuring%20Mappings%20(ELUG)|Creating and Configuring Mappings]]
+
* [[Configuring%20a%20Mapping%20(ELUG)|Configuring a Mapping]].
  
  
Line 131: Line 130:
  
 
Each direct collection stores reference information in a target table. In the [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Figure 32-6|Direct Collection Mappings]] figure, the <tt>RESPONS</tt> table contains the primary key and object of the instance owning the collection. You must create this table in your database.
 
Each direct collection stores reference information in a target table. In the [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Figure 32-6|Direct Collection Mappings]] figure, the <tt>RESPONS</tt> table contains the primary key and object of the instance owning the collection. You must create this table in your database.
 
  
  
Line 141: Line 139:
  
 
Use the '''Target Table''' list to select the table that contains the reference fields for the direct collection mapping.
 
Use the '''Target Table''' list to select the table that contains the reference fields for the direct collection mapping.
 
  
  
Line 152: Line 149:
 
* The database table that holds the values to be stored in the collection, set by using the <tt>setReferenceTableName</tt> method.
 
* The database table that holds the values to be stored in the collection, set by using the <tt>setReferenceTableName</tt> method.
 
* The field in the reference table from which the values are read and placed into the collection; this is called the direct field. Set it using the <tt>setDirectFieldName</tt> method.
 
* The field in the reference table from which the values are read and placed into the collection; this is called the direct field. Set it using the <tt>setDirectFieldName</tt> method.
* The foreign key information, which you specify using the <tt>setReferenceKeyFieldName</tt> method and passing the name of the field that is a foreign reference to the primary key of the source object
+
* The foreign key information, which you specify using the <tt>setReferenceKeyFieldName</tt> method and passing the name of the field that is a foreign reference to the primary key of the source object.
 +
 
 +
 
 
{| class="Note oac_no_warn" width="80%" border="1" frame="hsides" rules="groups" cellpadding="3" frame="hsides" rules="groups"
 
{| class="Note oac_no_warn" width="80%" border="1" frame="hsides" rules="groups" cellpadding="3" frame="hsides" rules="groups"
 
| align="left" |
 
| align="left" |
Line 162: Line 161:
 
''''' Configuring a Simple Direct Collection Mapping'''''
 
''''' Configuring a Simple Direct Collection Mapping'''''
 
  public void customize(ClassDescriptor descriptor) {  
 
  public void customize(ClassDescriptor descriptor) {  
     DirectCollectionMapping directCollectionMapping =  
+
     DirectCollectionMapping directCollectionMapping = new DirectCollectionMapping();
                                    new DirectCollectionMapping();
+
 
     directCollectionMapping.setAttributeName ("responsibilitiesList");
 
     directCollectionMapping.setAttributeName ("responsibilitiesList");
 
     directCollectionMapping.setReferenceTableName ("RESPONS"); '''// target table'''
 
     directCollectionMapping.setReferenceTableName ("RESPONS"); '''// target table'''
Line 186: Line 184:
  
 
The direct value field, located in the reference table, stores the primitive data value. In the [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Figure 32-6|Direct Collection Mappings]] figure, the <tt>DESCRIP</tt> field stores the collection.
 
The direct value field, located in the reference table, stores the primitive data value. In the [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Figure 32-6|Direct Collection Mappings]] figure, the <tt>DESCRIP</tt> field stores the collection.
 
  
  
Line 194: Line 191:
 
# Click the '''General''' tab. The General tab appears.<br><span id="Figure 41-2"></span>''''' General Tab, Direct Value Field'''''<br>[[Image:dcmapdir.gif|General Tab, Direct Value Field]]
 
# Click the '''General''' tab. The General tab appears.<br><span id="Figure 41-2"></span>''''' General Tab, Direct Value Field'''''<br>[[Image:dcmapdir.gif|General Tab, Direct Value Field]]
 
#Use the '''Direct Value Field''' list to select the field from the '''Target Table''' table that contains the object of the collection.
 
#Use the '''Direct Value Field''' list to select the field from the '''Target Table''' table that contains the object of the collection.
 
  
  
Line 207: Line 203:
  
 
[[Category: EclipseLink User's Guide]]
 
[[Category: EclipseLink User's Guide]]
[[Category: Draft]]
+
[[Category: Release 1]]
 
[[Category: Task]]
 
[[Category: Task]]
 
[[Category: ORM]]
 
[[Category: ORM]]

Latest revision as of 07:36, 20 August 2008

For information on how to create EclipseLink mappings, see Creating a Mapping.

This table lists the configurable options for a relational direct collection mapping.


Option Workbench Java

Target table

Supported

Supported

Direct value field

Supported

Supported

Method or direct field access

Supported

Supported

Read-only mapping

Supported

Supported

Batch reading

Supported

Supported

Indirection (lazy loading)

Supported

Supported

Container policy

Supported

Supported

Mapping comments

Supported

Supported

Configuring a Serialized Object Converter

Supported

Supported

Type conversion converter

Supported

Supported

Object type converter

Supported

Supported

Table and field references

Supported

Supported

This example shows how to create a direct collection mapping and add it to a descriptor using Java code.

Direct Collection Mapping

public void customize(ClassDescriptor descriptor) { 
    DirectCollectionMapping mapping = new DirectCollectionMapping();  

    // configure mapping
    ... 

    // add mapping to descriptor
    descriptor.addMapping(mapping);
}

For more information, see the following:


For information on using JPA to configure direct collection mappings, see How to Use the @BasicCollection Annotation.


Configuring Target Table

Each direct collection stores reference information in a target table. In the Direct Collection Mappings figure, the RESPONS table contains the primary key and object of the instance owning the collection. You must create this table in your database.


How to Configure a Target Table Using Workbench

To specify the direct collection specifics, use this procedure:

  1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.
  2. Click the General tab. The General tab appears.
    General Tab, Target Table Options
    General Tab, Target Table Options

Use the Target Table list to select the table that contains the reference fields for the direct collection mapping.


How to Configure a Target Table Using Java

Direct collection mappings store collections of Java objects that are not EclipseLink-enabled. Direct collections usually store Java types, such as String.

Direct collection mappings are instances of the DirectCollectionMapping class and require the following elements:

  • The attribute mapped, set by using the setAttributeName method.
  • The database table that holds the values to be stored in the collection, set by using the setReferenceTableName method.
  • The field in the reference table from which the values are read and placed into the collection; this is called the direct field. Set it using the setDirectFieldName method.
  • The foreign key information, which you specify using the setReferenceKeyFieldName method and passing the name of the field that is a foreign reference to the primary key of the source object.


Note: If the target primary key is composite, call the addReferenceKeyFieldName method for each of the fields that make up the key.


Configuring a Simple Direct Collection Mapping

public void customize(ClassDescriptor descriptor) { 
    DirectCollectionMapping directCollectionMapping = new DirectCollectionMapping();
    directCollectionMapping.setAttributeName ("responsibilitiesList");
    directCollectionMapping.setReferenceTableName ("RESPONS"); // target table
    directCollectionMapping.setDirectFieldName ("DESCRIP");
    directCollectionMapping.setReferenceKeyFieldName ("EMP_ID");
    directCollectionMapping.useCollectionClass (Collection.class); // default

    // add this mapping to descriptor
    descriptor.addMapping (directCollectionMapping);
}

In addition to the API that the Configuring a Simple Direct Collection Mapping example illustrates, other common API for use with direct collection mappings include the following:

  • useBasicIndirection: implements EclipseLink value holder indirection.
  • useTransparentCollection: if you use transparent indirection, this element places a special collection in the source object's attribute.
  • dontUseIndirection: implements no indirection.

For more information about the available methods for DirectCollectionMapping, see the EclipseLink API Reference.


Configuring Direct Value Field

The direct value field, located in the reference table, stores the primitive data value. In the Direct Collection Mappings figure, the DESCRIP field stores the collection.


How to Configure a Direct Value Field Using Workbench

To specify the direct collection specifics, use this procedure:

  1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.
  2. Click the General tab. The General tab appears.
    General Tab, Direct Value Field
    General Tab, Direct Value Field
  3. Use the Direct Value Field list to select the field from the Target Table table that contains the object of the collection.


How to Configure Direct Value Field Using Java

The Configuring a Simple Direct Collection Mapping example demonstrates how to create and configure a direct collection mapping, including the setting of a direct field. The example also shows how to add this mapping to the descriptor.



Copyright Statement

Back to the top