Cascade and orphanRemoval

cascade propagates an operation (PERSIST, MERGE, REMOVE, ALL) from a parent entity to its children. orphanRemoval = true deletes a child removed from the parent's collection. They suit children whose lifecycle depends on the parent, such as the lines of an order.

Example

@OneToMany(mappedBy = "commande", cascade = CascadeType.ALL, orphanRemoval = true)
List<Ligne> lignes;

Related concepts

The whole glossary