Creating Many-to-Many Mappings

Use this procedure to create a many-to-many mapping.

To create a many-to-many mapping:

  1. In the Application Navigator, select the attribute to be mapped.
  2. Click the Many-to-Many Mapping button Many-to-many Mapping button. on the mapping toolbar.

    Figure 7-9 Many-to-Many Mapping General Properties

    This figure shows the General tab for a many-to-many mapping.

  3. Use the Reference Descriptor drop-down list to choose the reference descriptor for this mapping.
  4. Use the Relation Table drop-down list to choose the relation table.
  5. Use the Maintain Bidirectional Relationship option to select a Relationship Partner for this mapping. See "Maintaining Bidirectional Relationships" for more information.
  6. Modify any other properties, as needed. See "Working with Common Mapping Properties" for more information.
  7. Click the Collection Options tab to specify how the source descriptor relates to the relation table. See "Specifying Collection Properties" for more information.
  8. Click the Source Reference tab to specify how the source descriptor relates to the relation table.

    Figure 7-10 Many-to-Many Mapping Source Reference Properties

    This figure shows the ource Reference tab for a many-to-many mapping.

  9. Use the Table Reference drop-down list to choose a reference whose foreign key is in the relation table and that points to a table associated to the source descriptor.
  10. Click the Target Reference tab to specify how the reference descriptor relates to the relation table.
  11. Choose a reference whose foreign key is in the relation table and that points to a table associated to the reference descriptor.

Specifying Advanced Features by Amending the Descriptor

TopLink can populate a collection in ascending or descending order, upon your specification. To do this, specify and write an amendment method, sending the addAscendingOrdering() or addDescendingOrdering() to the many-to-many mapping. Both messages expect a string as a parameter, which indicates what attribute from the target object is used for the ordering. This string can be an attribute name or query key from the target's descriptor. Query keys are automatically created for and with the same name as all attributes mapped as direct-to-field, type conversion, object type, and serialized object mappings.

 

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