| Oracle® TopLink Developer's Guide 10g (10.1.3.1.0) B28218-01 |
|
![]() 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 thanVector 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.
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.
Use one-to-many mappings for relationships between entity beans or between an entity bean and a collection of privately owned regular Java objects. When you create one-to-many mappings, also create a one-to-one mapping from the target objects back to the source. The object attribute that contains a pointer to the bean must be the local interface type–not the bean class.
TopLink automatically maintains back-pointers when you create or update bidirectional relationships between beans.
For more information, see "Configuring Bidirectional Relationship".