Mapping One-to-one Associations

EJB 3 persistence supports both bi-directional one-to-one association mapping and unidirectional one-to-one association mapping.

The OneToOne annotation is generated to define a single-valued association to another entity that has one-to-one multiplicity. For bi-directional one-to-one associations, the generated annotations will resemble:

@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumns({
  @JoinColumn(name="aid", referencedColumnName="aid")
})
public Account getAccount() { ... }

@OneToOne(cascade=CascadeType.PERSIST, mappedBy="account")
public Person getPerson() { ... }

Generated annotations for unidirectional one-to-one associations are similar. A model check is available to verify that mappings are correctly defined for unidirectional one-to-one associations. One unidirectional association can only be mapped to a reference that has the same direction as the association.

For more informations about mapping, see O/R Mapping Modeling.