Create one-to-many mappings |
Use a One-to-Many Mapping to define a relationship from an attribute to another class, with one-to-many multiplicity to a database column. In the Tutorial Object Model, the phoneNumbers field of the Employee class has a one-to-many relationship to the Phone class; each employee may have many phone numbers.
Select the Employee entity in the Package Explorer view.
In the JPA Structure view, select the phoneNumber 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-Many.
Select PhoneNumber as the Target Entity. Leave the other fields with their default values.
In the Join Table area, notice that Dali has selected the correct joins, based on the foreign key associations in the database tables.
In the JPA Structure, the phoneNumbers field is identified as a one-to-many mapping as shown in the following figure:
Next, you will Create many-to-one mappings.