# Many-to-one mapping

Use a Many-to-One mapping to defines a single-valued association to another entity class that has many-to-one multiplicity.

1. In the JPA Structure view, select the field to map.

2. Right click the field and then select Map As > Many-to-One. The JPA Details view (for attributes) displays the properties for the selected.

3. Use this table to complete the General information fields JPA Details view.

   Property | Description | Default
   --- | --- | ---
   Mapping Entity Hyperlink | Defines mapping as Many-to-One. This corresponds to the `@ManyToOne` annotation. | Many-to-One
   Target Entity | The entity to which this attribute is mapped. | null You do not need to explicitly specify the target entity, since it can be inferred from the type of object being referenced.
   Fetch | Defines how data is loaded from the database. See "Fetch Type" for details. Eager Lazy | Eager
   Cascade | See "Cascade Type" for details. Default All Persist Merge Remove | Default
   Optional | Specifies if this field is can be null. | Yes

4. Use this table to complete the fields on the Join Columns Information tab in the JPA Details view.

   Property | Description | Default
   --- | --- | ---
   Join Column | Specify a mapped column for joining an entity association. This field corresponds to the `@JoinColum` attribute. Select Override Default, then Add, Edit, or Remove the join columns. | By default, the mapping is assumed to have a single join.

Eclipse adds the following annotations to the field:

    @JoinTable(joinColumns=@JoinColumn(name="<JOIN_COLUMN>"),
        name = "<JOIN_TABLE_NAME>")
    @ManyToOne(targetEntity=<TARGET_ENTITY>, fetch=<FETCH_TYPE>,
        cascade=<CASCADE_TYPE>)

Mapping an entity

JPA Structure view
JPA Details view (for attributes)

Understanding OR mappings
Understanding EJB 3.0 Java Persistence API