I don't get it. Table design was done prior to any java code and it was designed to have only one link table. what do you mean it will create two different join tables ?
Then the mapping to that existing table is not conform how a bidrectional many-to-many relationship should be mapped according to the JPA specifications.
The specification clearly states that the
mappedBy attribute is needed for a bi-directional relationship.
2.9 Entity Relationships
The following rules apply to bidirectional relationships:
- The inverse side of a bidirectional relationship must refer to its owning side by use of the mappedBy element of the OneToOne, OneToMany, or ManyToMany annotation. The mappedBy element designates the property or field in the entity that is the owner of the relationship.
... left out the other rules
I was just telling you that you don't see your mistake because you point from both unidirectional many-to-many sides to the same join table. Leaving out the
mappedBy attribute by a many-to-many relationship creates an unidirectional relationship with a join-table by default (and in this case two).