Mapping Many-to-many Associations

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

A ManyToMany annotation is generated to define a many-valued association with many-to-many multiplicity.

@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
  name="Assignment",
  joinColumns={
   @JoinColumn(name="eid", referencedColumnName="eid")
  },
  inverseJoinColumns={
   @JoinColumn(name="tid", referencedColumnName="tid")
  }
)
public java.util.Collection<Title> getTitle() { ... }

A model check is available to verify that mappings are correctly defined for many-to-many associations. Middle tables are needed for many-to-many association mapping.

For more informations about mapping, see Object/Relational (O/R) Mapping.