Convenient on a true parent-child relationship, dangerous on a shared reference.
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderItem> items = new ArrayList<>();
// Correct - items only exist inside an order.
@ManyToOne(cascade = CascadeType.ALL) // WRONG
private Customer customer; // deleting an order deletes the customer
orphanRemoval = true: removing an item from the list deletes the row.
cascade on a @ManyToOne to a shared entity is nearly always a bug.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11