Create One-to-One Mappings


Use a One-to-One Mapping to define a relationship from an attribute to another class, with one-to-one multiplicity to a database column. In the Tutorial Object Model, the address field of the Employee class has a one-to-one relationship to the Address class; each employee may have a single address.

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

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

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

    One-to-one Mapping for address

    This figure shows the Persistence Properties page for the firstName field.
  4. For the Target Entity, click Browse and select the Address persistent entity. Dali adds the @OneToOne(targetEntity=dali.tutorial.model.Address.class) entity to the class.

  5. The Join Column fields specify the relationship between the Employee and Address entities. In the Name field select ADDR_ID (from the EMPLOYEE table); in the Reference Column field select ADDRESS_ID (from the ADDRESS table).

    Leave the other fields with their default values.

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

Persistence Outline for Employee Entity

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

Next, you will Create One-to-Many Mappings.