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 JPA Structure view, select the address field of the Employee entity. The JPA Details 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.
Leave the other fields with their default values.
Select the Join Columns tab to specify the relationship between the Employee and Address entities. Because you had to explicitly define the ID field for the Address entity in its ID mapping, you will need to edit the default join relationship.
Select the Override Default option.
Select the address_ADDRESS_ID -> ADDRESS_ID relationship in the Join Columns area and click Edit.
In the Edit Join Column dialog, select the following options and click OK.
Name: ADDR_ID (from the EMPLOYEE table)
Referenced Column Name: ADDRESS_ID (from the ADDRESS table)
In the JPA Structure, 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.