# One-to-many mapping

Use a One-to-Many Mapping to define a relationship with one-to-many multiplicity.

1. In the Persistence Outline view, select the field to map. The Persistence Properties view (for attributes) displays the properties for the selected.

2. In the Map As field, select One-to-many.

3. Use this table to complete the fields on the General tab in the Persistence Properties view.

   Property | Description | Default
   --- | --- | ---
   Target Entity | The entity to which this attribute is mapped. |

   Cascade Type

   See "Cascade Type" for details.

   - Default

   - All

   - Persist

   - Merge

   - Remove

   Fetch Type

   Defines how data is loaded from the database. See "Fetch Type" for details.

   - Eager

   - Lazy

   Eager

   Mapped By | The database field that owns the relationship. |

   Order By

   Specify the default order for objects returned from a query. See "Order By" for details.

   - Primary key

   Primary key

4. Use this table to complete the fields on the Join Table tab in the Persistence Properties view.

   Property | Description | Default
   --- | --- | ---
   Name | Name of the join table | By default, the name is assumed to be the primary tables associated with the entities concatenated with an underscore.
   Join Columns | Specify two or more join columns (that is, a primary key). |
   Inverse Join Columns | The join column on the owned (or inverse) side of the association: the owned entity's primary key column. |

Eclipse adds the following annotations to the field:

    @OneToMany(targetEntity=<TARGET_ENTITY>)
    @Column(name="<COLUMN>")

    @OneToMany(targetEntity=<TARGET_ENTITY>.class, cascade=CascadeType.<CASCADE_TYPE>,
        fetch = FetchType.<FETCH_TYPE>, mappedBy = "<MAPPED_BY>")@OrderBy("<ORDER_BY>")
    @JoinTable(name="<JOIN_TABLE_NAME>", joinColumns=@JoinColumn(name=
        "<JOIN_COLUMN_NAME>", referencedColumnName="<JOIN_COLUMN_REFERENCED_COLUMN>"),
        inverseJoinColumns=@JoinColumn(name="<INVERSE_JOIN_COLUMN_NAME>",
        referencedColumnName="<INVERSE_JOIN_COLUMN_REFERENCED_COLUMN>"))

Mapping an entity

Persistence Outline view
Persistence Properties view (for attributes)

Understanding OR mappings
Understanding JSR220: EJB 3.0