Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "Configuring a Relational Many-to-Many Mapping (ELUG)"

m (Configuring a Relation Table)
Line 7: Line 7:
 
For information on how to create EclipseLink mappings, see [[Creating%20a%20Mapping%20(ELUG)|Creating a Mapping]].
 
For information on how to create EclipseLink mappings, see [[Creating%20a%20Mapping%20(ELUG)|Creating a Mapping]].
  
[[#Table 39-1|Configurable Options for Relational Many-to-Many Mapping]] lists the configurable options for a relational many-to-many mapping.
 
 
 
 
==Introduction to Relational Many-to-Many Mapping Configuration==
 
  
 
This table lists the configurable options for a relational many-to-many mapping.
 
This table lists the configurable options for a relational many-to-many mapping.
 
  
 
<span id="Table 39-1">
 
<span id="Table 39-1">
''''' Configurable Options for Relational Many-to-Many Mapping'''''
 
  
{| class="RuleFormalMax" dir="ltr" title="Configurable Options for Relational Many-to-Many Mapping" summary="This table lists the configurable options common to Relational Many-to-Many Mapping and categorizes them as Basic and Advanced and indicates if the option can be configured with the TopLink Workbench, Java, or both." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
+
{| class="RuleFormalMax" dir="ltr" title="Configurable Options for Relational Many-to-Many Mapping" summary="This table lists the configurable options common to Relational Many-to-Many Mapping and categorizes them as Basic and Advanced and indicates if the option can be configured with the Workbench, Java, or both." width="100%" border="1" frame="border" rules="all" cellpadding="3" frame="border" rules="all"
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
! id="r1c1-t2" align="left" valign="bottom" | '''Option to Configure'''
 
! id="r1c1-t2" align="left" valign="bottom" | '''Option to Configure'''
Line 26: Line 19:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r2c1-t2" headers="r1c1-t2" align="left" |
 
| id="r2c1-t2" headers="r1c1-t2" align="left" |
Reference descriptor (see [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring Reference Descriptor]])
+
Reference descriptor (see [[Configuring%20a%20Relational%20Mapping%20(ELUG)#Configuring Reference Descriptor|Configuring Reference Descriptor]])
 
| headers="r2c1-t2 r1c2-t2" align="left" |
 
| headers="r2c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 33: Line 26:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r3c1-t2" headers="r1c1-t2" align="left" |
 
| id="r3c1-t2" headers="r1c1-t2" align="left" |
Method or direct field access (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring a Type Conversion Converter]])
+
Method or direct field access (see [[Configuring%20a%20Mapping%20(ELUG)#Configuring a Type Conversion Converter|Configuring a Type Conversion Converter]])
 
| headers="r3c1-t2 r1c2-t2" align="left" |
 
| headers="r3c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 40: Line 33:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r4c1-t2" headers="r1c1-t2" align="left" |
 
| id="r4c1-t2" headers="r1c1-t2" align="left" |
Read-only mapping (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Read-Only Mappings]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Read-Only Mappings|Read-only mapping]]
 
| headers="r4c1-t2 r1c2-t2" align="left" |
 
| headers="r4c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 47: Line 40:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r5c1-t2" headers="r1c1-t2" align="left" |
 
| id="r5c1-t2" headers="r1c1-t2" align="left" |
Private or Independent relationships (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Mapping Comments]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Private or Independent relationships|Private or Independent relationships]]
 
| headers="r5c1-t2 r1c2-t2" align="left" |
 
| headers="r5c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 54: Line 47:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r6c1-t2" headers="r1c1-t2" align="left" |
 
| id="r6c1-t2" headers="r1c1-t2" align="left" |
Batch reading (see [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring Batch Reading]])
+
[[Configuring%20a%20Relational%20Mapping%20(ELUG)#Configuring Batch Reading|Batch reading]]
 
| headers="r6c1-t2 r1c2-t2" align="left" |
 
| headers="r6c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 61: Line 54:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r7c1-t2" headers="r1c1-t2" align="left" |
 
| id="r7c1-t2" headers="r1c1-t2" align="left" |
Indirection (lazy loading) (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Mapping Comments]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Indirection (lazy loading)|Indirection (lazy loading)]]
 
| headers="r7c1-t2 r1c2-t2" align="left" |
 
| headers="r7c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 68: Line 61:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r8c1-t2" headers="r1c1-t2" align="left" |
 
| id="r8c1-t2" headers="r1c1-t2" align="left" |
Bidirectional relationship (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Bidirectional Relationship]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Bidirectional Relationship|Bidirectional relationship ]]
 
| headers="r8c1-t2 r1c2-t2" align="left" |
 
| headers="r8c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 75: Line 68:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r9c1-t2" headers="r1c1-t2" align="left" |
 
| id="r9c1-t2" headers="r1c1-t2" align="left" |
Container policy (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Mapping Comments]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Mapping Comments|Container policy]]
 
| headers="r9c1-t2 r1c2-t2" align="left" |
 
| headers="r9c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 82: Line 75:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r10c1-t2" headers="r1c1-t2" align="left" |
 
| id="r10c1-t2" headers="r1c1-t2" align="left" |
Mapping comments (see [[Configuring%20a%20Mapping%20(ELUG)|Configuring Mapping Comments]])
+
[[Configuring%20a%20Mapping%20(ELUG)#Configuring Mapping Comments|Mapping comments]]
 
| headers="r10c1-t2 r1c2-t2" align="left" |
 
| headers="r10c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 89: Line 82:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r11c1-t2" headers="r1c1-t2" align="left" |
 
| id="r11c1-t2" headers="r1c1-t2" align="left" |
Relational table (see [[#Configuring a Relation Table]])
+
[[#Configuring a Relation Table|Relational table ]]
 
| headers="r11c1-t2 r1c2-t2" align="left" |
 
| headers="r11c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 110: Line 103:
 
|- align="left" valign="top"
 
|- align="left" valign="top"
 
| id="r14c1-t2" headers="r1c1-t2" align="left" |
 
| id="r14c1-t2" headers="r1c1-t2" align="left" |
Query key order (see [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring Query Key Order]])
+
[[Configuring%20a%20Relational%20Mapping%20(ELUG)#Configuring Query Key Order|Query key order ]]
 
| headers="r14c1-t2 r1c2-t2" align="left" |
 
| headers="r14c1-t2 r1c2-t2" align="left" |
 
[[Image:support.gif|Supported]]
 
[[Image:support.gif|Supported]]
Line 136: Line 129:
  
 
For more information, see the following:
 
For more information, see the following:
 
 
* [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Many-to-Many Mapping|Many-to-Many Mapping]]
 
* [[Introduction%20to%20Relational%20Mappings%20(ELUG)#Many-to-Many Mapping|Many-to-Many Mapping]]
 
* [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring a Relational Mapping]]
 
* [[Configuring%20a%20Relational%20Mapping%20(ELUG)|Configuring a Relational Mapping]]
Line 147: Line 139:
  
 
==Configuring a Relation Table==
 
==Configuring a Relation Table==
 
 
The relation table contains the columns for the primary keys of the source table and target table involved in the many-to-many mapping. You must create this table in the database before completing the mapping. See [[Using%20Workbench%20(ELUG)#Using Databases|Using Databases]] for information on creating database tables.
 
The relation table contains the columns for the primary keys of the source table and target table involved in the many-to-many mapping. You must create this table in the database before completing the mapping. See [[Using%20Workbench%20(ELUG)#Using Databases|Using Databases]] for information on creating database tables.
  
Line 209: Line 200:
 
[[Category: Draft]]
 
[[Category: Draft]]
 
[[Category: Task]]
 
[[Category: Task]]
 +
[[Category: ORM]]

Revision as of 16:42, 14 December 2007

This section describes the various components that you must configure in order to use a relational many-to-many mapping.

For information on how to configure EclipseLink mappings options common to two or more mapping types, see Configuring a Mapping.

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


This table lists the configurable options for a relational many-to-many mapping.

Option to Configure Workbench Java

Reference descriptor (see Configuring Reference Descriptor)

Supported

Supported

Method or direct field access (see Configuring a Type Conversion Converter)

Supported

Supported

Read-only mapping

Supported

Supported

Private or Independent relationships

Supported

Supported

Batch reading

Supported

Supported

Indirection (lazy loading)

Supported

Supported

Bidirectional relationship

Supported

Supported

Container policy

Supported

Supported

Mapping comments

Supported

Supported

Relational table

Supported

Supported

Table and field references (see Configuring Joining at the Mapping Level) (Source)

Supported

Supported

Table and field references (see Configuring Joining at the Mapping Level) (Target)

Supported

Supported

Query key order

Supported

Supported


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

Many-to-Many Mapping

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

    // configure mapping
    ... 

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

For more information, see the following:


For information on using JPA to configure many-to-many mappings, see @ManyToMany.


Configuring a Relation Table

The relation table contains the columns for the primary keys of the source table and target table involved in the many-to-many mapping. You must create this table in the database before completing the mapping. See Using Databases for information on creating database tables.

In the Many-to-many Relationships figure, the PROJ_EMP table serves as the relation table between the PROJECT and EMPLOYEE tables.


How to Configure a Relation Table Using Workbench

To select a relation table for a mapping, 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.
    Table Reference Tab, Relation Table Option
    Table Reference Tab, Relation Table Option
  3. Use the Relation Table field to select a database table to define this mapping.



How to Configure a Relation Table Using Java

Many-to-many mappings represent the relationships between a collection of source objects and a collection of target objects. This requires an intermediate table that manages the associations between the source and target records.

Many-to-many mappings are instances of the ManyToManyMapping class and requires the following elements:

  • The attribute mapped, set by using the setAttributeName method.
  • The reference class, set by using the setReferenceClass method.
  • The relation table, set by using the setRelationTableName() method.
  • The foreign key information (for noncomposite target primary keys), which you specify by calling the setSourceRelationKeyFieldName and setTargetRelationKeyFieldName methods.
  • The foreign key information if the source or target primary keys are composite, which you specify by sending the addSourceRelationKeyFieldName or addTargetRelationKeyFieldName methods.


Configuring a Relational Table

public void customize(ClassDescriptor descriptor) { 
    // In the Employee class, create the mapping that references Project class
    ManyToManyMapping manyToManyMapping = new ManyToManyMapping();
    manyToManyMapping.setAttributeName("projects");
    manyToManyMapping.setReferenceClass(Project.class);

    // Configure the relational table
    manyToManyMapping.setRelationTableName("PROJ_EMP");
    manyToManyMapping.setSourceRelationKeyFieldName ("EMPID");
    manyToManyMapping.setTargetRelationKeyFieldName ("PROJID");

    // Add mapping to descriptor

    descriptor.addMapping(manyToManyMapping);
}

In addition to the API that Configuring a Relational Table illustrates, other common API for use with many-to-many 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 ManyToManyMapping, see the EclipseLink API Reference.




Copyright Statement

Back to the top