Cascade Types, Orphan Removal and Fetch Types (Lazy vs Eager)
Learn Cascade Types, Orphan Removal and Fetch Types (Lazy vs Eager) (Phase 4 · Entity Relationships (Essential), Hibernate) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Cascade types • Cascading propagates an operation from a parent to its associated entities. CascadeType : PERSIST , MERGE , REMOVE , REFRESH , DETACH , ALL (all of them), plus Hibernate's @Cascade(SAVE_UPDATE...) (legacy). • Use cascade for composition (the child cannot exist without the parent: order → order lines, course → lessons). Do not cascade to independent aggregates (course → category, student → country) and never REMOVE / ALL on @ManyToMany or @ManyToOne . • Cascading REMOVE loads the children and issues one DELETE per child (slow for large collections): consider @OnDelete(action =...