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.
Select the Employee entity in the Package Explorer view.
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.
In the Map As field, select One-to-One.
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.
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:
Next, you will Create One-to-Many Mappings.