What set of annotations correctly defines the association?

Given two entities with many-to-many bidirectional association between them:

What set of annotations correctly defines the association?

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



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Andrei

Andrei

C , but it should have been Project.class and not project.class

test

test

I tested it “D” works fine, Please test before taking “C” as grant.
Tested with EclipseLink which is more with JPA standard than Hibernate

test

test

D is incorrect, C is correct

Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

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.

Lejmi Salah

Lejmi Salah

C is correct: bidirectional association
D is incorrect: no “mappedBy” element specified => 2 different unidirectional relationships