Skip Headers

# One-to-Many Mapping

Previous

Next

One-to-many mappings are used to represent the relationship between a single source object and a collection of target objects. They are a good example of something that is simple to implement in Java using a `Vector` (or other collection types) of target objects, but difficult to implement using relational databases.

In a Java `Vector`, the owner references its parts. In a relational database, the parts reference their owner. Relational databases use this implementation to make querying more efficient.

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

The purpose of creating this one-to-one mapping in the target is so that the foreign key information can be written when the target object is saved. Alternatives to the one-to-one mapping back reference include the following:

- Use a direct-to-field mapping to map the foreign key and maintain its value in the application. Here the object model does not require a back reference, but the data model still requires a foreign key in the target table.

- Use a many-to-many mapping to implement a logical one-to-many. This has the advantage of not requiring a back reference in the object model and not requiring a foreign key in the data model. In this model the many-to-many relation table stores the collection. It is possible to put a constraint on the join table to enforce that the relation is a logical one-to-many relationship.

One-to-Many Relationships

Description of "One-to-Many Relationships "

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

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