Create Many-to-One Mappings


Use a May-to-One Mapping to define a relationship from an attribute to another class, with many-to-one multiplicity to a database column. In the Tutorial Object Model, the owner field of the PhoneNumber class has a one-to-many relationship to the Employee class; there are many phone numbers that each employee may have.

This is the "back mapping" of the one-to-many mapping you previously defined.

  1. Select the PhoneNumber entity in the Package Explorer view.

  2. In the Persistence Outline View, select the owner field of the PhoneNumber entity. The Persistence Properties View (for Attributes) displays the properties for the field.

  3. In the Map As field, select Many-to-One.

    Version Mapping for owner

    This figure shows the Persistence Properties page for the firstName field.
  4. Leave the other fields with their default values. Dali correctly completes the information based on the database structure and previously defined mappings.

In the Persistence Outline, the owner field is identified as a many-to-one mapping as shown in the following figure:

Persistence Outline for PhoneNumber Entity

This figure shows the emp_id attribute of the Employee entity in the Persistence Outline view.

Next, you will Create Version Mappings