Many-to-many mapping

Use a Many-to-Many Mapping to define a many-valued association with many-to-many multiplicity. A many-to-many mapping has two sides: the owning side and non-owning side. You must specify the join table on the owning side. For bidirectional mappings, either side may be the owning side.

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

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

    JPA Details, Many to many mapping

    JPA Details, Primary key generation
  3. Complete each field in the Many-to-Many Mapping area.

  4. Use the Joining Strategy area to specify the join strategy (or table) for the mapping.

    JPA Details, Joining Strategy

    JPA Details, Joining Strategy
  5. Complete each field in the Joining Strategy area.

  6. Complete the remaining areas in the JPA Details view (for attributes).

Eclipse adds the following annotations to the field:

@JoinTable(
    joinColumns=@JoinColumn(name="<JOIN_COLUMN>"), 
    name = "<JOIN_TABLE_NAME>"
)
@ManyToMany(=Type.<_TYPE>, fetch=FetchType.<FETCH_TYPE>,
    targetEntity=<TARGET_ENTITY>, mappedBy = "<MAPPED_BY>")
@OrderBy("<ORDER_BY>")

Related tasks

Related references

Related concepts