Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Many-to-Many Mapping

Many-to-many mappings represent the relationships between a collection of source objects and a collection of target objects. They require the creation of an intermediate table for managing the associations between the source and target records.

Figure 36-5 illustrates a many-to-many mapping in Java and in relational database tables.

Figure 36-5 Many-to-many Relationships

Description of "Figure 36-5 Many-to-many Relationships"

Many-to-many mappings are implemented using a relation table. This table contains columns for the primary keys of the source and target tables. Composite primary keys require a column for each field of the composite key. The intermediate table must be created in the database before using the many-to-many mapping.

The target class does not have to implement any behavior for the many-to-many mappings. If the target class also creates a many-to-many mapping back to its source, then it can use the same relation table, but one of the mappings must be set to read-only. If both mappings write to the table, they can cause collisions.

Note: See "Configuring Container Policy"for information on using `Collection` classes other than `Vector` with one-to-many mappings.

Indirection is enabled by default in a many-to-many mapping, which requires that the attribute have the `ValueHolderInterface` type or transparent collections.

You can use a many-to-many mapping with a change policy (see "Configuring Change Policy".

See "Configuring a Relational Many-to-Many Mapping" for more information.

## Many-to-Many Mappings and EJB

When you use CMP, many-to-many mappings are valid only between entity beans, and cannot be privately owned. The only exception is when a many-to-many mapping is used to implement a logical one-to-many mapping with a relation table.

TopLink automatically maintains back-pointers when you create or update bidirectional relationships.

For more information, see "Configuring Bidirectional Relationship".