Java Persistence/ManyToMany - Wikibooks, open books for an open world - 0 views
-
Bi-directional Many to Many
- ...9 more annotations...
-
one direction must be defined as the owner and the other must use the mappedBy attribute to define its mapping
-
If the mappedBy is not used, then the persistence provider will assume there are two independent relationships
-
As with all bi-directional relationships it is your object model's and application's responsibility to maintain the relationship in both direction
-
To make your life simpler, I would recommend adding a generated Id attribute to the association class
-
Another usage is if you have a Map relationship between two objects, with a third unrelated object or data representing the Map key