One-to-one mapping

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

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

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

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

    Property Description Default
    Mapped Entity Hyperlink Defines mapping as One-to-One. This corresponds to the @OneToOne annotation. One-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 Type Defines how data is loaded from the database. See "Fetch Type" for details.
    • Eager

    • Lazy

    Mapped By The database field that owns the relationship.

  4. Use this table to complete the Join Columns Information fields 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:

@OneToOne(targetEntity=<TARGET_ENTITY>, cascade=CascadeType.<CASCADE_TYPE>, 
    fetch = FetchType.<FETCH_TYPE>, mappedBy = "<MAPPED_BY>")
@JoinColumn(name="<JOIN_COLUMN_NAME>", referencedColumnName=
    updatable = <UPDATABLE>)


Related task

Mapping an entity


Related reference

JPA Structure view
JPA Details view (for attributes)


Related concept

Understanding OR mappings
Understanding EJB 3.0 Java Persistence API