intermediateRelationships — @OneToMany, @ManyToOne, @ManyToMany, Cascade & FetchType

What does mappedBy actually do in a bidirectional @OneToMany/@ManyToOne relationship?

It marks the @OneToMany side as the inverse (non-owning) side, telling Hibernate the foreign key already lives on the other (@ManyToOne) side's table — so Hibernate doesn't create a separate join table for this relationship. Changes must be made (and persisted) via the owning side; mutating only the inverse side's collection without updating the owning side won't persist.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why is defaulting every relationship to CascadeType.ALL a common real production mistake?← Back to all Spring Data JPA & Hibernate Mastery questions