hiddenuser
hiddenuser

Reputation: 535

JPA @ManyToOne no mappedBy attribute exist

Why doesn't the @ManyToOne JPA specification have a mappedBy attribute? @ManyToOne has both unidirectional and bidirectional relationships, but @OneToMany has only unidirectional relationships. Why is that?

Upvotes: 5

Views: 1318

Answers (1)

JB Nizet
JB Nizet

Reputation: 692121

Because the spec mandates that in a bidirectional OneToMany/ManyToOne association, the Many side must be the owner side (and thus doesn't need a mappedBy attribute), and the One side must be the inverse side (and thus needs a mappedBy attribute).

Upvotes: 7

Related Questions