One-to-Many Association Mapping Strategy

Each unidirectional many-to-one association is mapped to a reference that has the same direction as the association.

In the following example, a unidirectional many-to-one association defined between the class Customer and the class Order is mapped to the reference key:
Classes Tables




Each unidirectional one-to-many association should be mapped to a middle table and two references that refer to tables mapped by the entity classes on both ends.

In the following example, the association defined between Customer and Order is a unidirectional one-to-many association mapped to a middle table and reference keys:
Classes Tables
orm48

You can map a bi-directional one-to-many association as unidirectional many-to-one association. The reference just can navigate from primary table of class on multiple-valued side to primary table of class on single-valued side.

Sometimes we want to make the primary key of parent table be part of primary key of the child table and reference key join on the migrated column(s). For example we can map Customer, Order and bi-directional one-to-many association to tables and reference key as follows:



In order to define such type of association mapping, you have to define the association as composition with the class on single-valued side containing the class on multiple-valued side first.



The association is the following:



Then add the reference as mapping sources. You just can define the same way association mapping for bi-directional one-to-many association.