Given two entities with many-to-many bidirectional association between them:
What set of annotations correctly defines the association?
A.
@manyToMany on the projects field,
@manyToMany (mappedBy= �projects�) on the emps field
B.
@manyToMany (mappedBy = emps) on the projects field,
@manyToMany on the emps field
C.
@manyToMany ()targetEntity = project.class) on the projects field,
@manyToMany (mappedBy = �projects�) on the emps field
D.
@manyToMany (targetEntity = Project.class) on the projects field,
@manyToMany on the emps field
C
C is correct: http://uaihebert.com/jpa-manytomany-unidirecional-e-bidirecional/
C , but it should have been Project.class and not project.class
I tested it “D” works fine, Please test before taking “C” as grant.
Tested with EclipseLink which is more with JPA standard than Hibernate
D is incorrect, C is correct
D is not correct because the relationship is bidirectional, as they claimed in the question, and that’s why the non-owning side must use the mappedBy element. Every bidirectional relationship has to have both an owning side and an inverse side and we must pick one of the two entities to be the owner. Note that no matter which side is designated as the owner, the other side should include the mappedBy element; otherwise, the provider will think that both sides are the owner and that the mappings are separate unidirectional relationships.
C is correct: bidirectional association
D is incorrect: no “mappedBy” element specified => 2 different unidirectional relationships