Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

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:

Figure 6-23 One-to-Many Mapping 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.One-to-Many Relationships

Description of 1mmapfig.gif follows
Description of the illustration 1mmapfig.gif

Creating One-to-Many Mappings

Use this procedure to create a one-to-many mapping in the OracleAS TopLink Mapping Workbench.

To create a one-to-many mapping:

  1. Select the attribute to be mapped from the Navigator pane.

  2. One to Many mapping button.
    Description of the illustration 1mmapbtn.gif

    Click the One-to-Many Mapping button on the mapping toolbar.

    Figure 6-24 One-to-many mapping General Properties

    Description of 1mmapge.gif follows
    Description of the illustration 1mmapge.gif

  3. Use the Reference Descriptor drop-down list to choose the reference for this descriptor.

  4. You can also specify:

    • Bidirectional relationships – See "Maintaining Bidirectional Relationships" on page 4-73.

    • Read-only attributes – See "Specifying Read-Only Settings" on page 4-72.

    • Access methods – See "Specifying Direct Access and Method Access" on page 4-71.

    • Null values – See "Defaulting Null Values" on page 4-73.

  5. Click the Table References tab to specify foreign key information for this mapping. See "Creating Table References" on page 3-6 for more information.