Working with One-to-Many Mappings

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 "Working with a 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:

One-to-many mappings must put the foreign key in the target table, rather than the source table. The target class should also implement a one-to-one mapping back to the source object, as illustrated in the following figure.

Figure 5-16 One-to-Many Relationships

This figure shows a one-to-many relationship in Java and a relational database.


Related Topics

About TopLink Mapping Types
Working with Relationship Mappings

 

Creating One-to-Many Mappings for Java Objects
Creating One-to-Many Mappings for CMP EJBs

 

Copyright © 1997, 2004, Oracle. All rights reserved.