intermediate~5h
Relationships — @OneToMany, @ManyToOne, @ManyToMany, Cascade & FetchType
Every relationship in your entity model requires a deliberate answer to "what happens to the children when the parent changes" and "should this load immediately or on demand" — getting these two decisions wrong is the most common source of both accidental cascading deletes and N+1 query problems.
Learning objectives
- Explain owning side vs. inverse side in a bidirectional relationship and what mappedBy actually does.
- Choose cascade and orphanRemoval settings deliberately based on a relationship's actual ownership semantics.
- Explain why FetchType.LAZY should be the default and identify JPA's actual (often-surprising) default for @ManyToOne/@OneToOne.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.
Relationships — @OneToMany, @ManyToOne, @ManyToMany, Cascade & FetchType