Cascading deletion propagates removal from an owning entity to associated entities. For an Item with dependent Bid entities, deleting the Item can remove every associated Bid automatically. section 8.3.3
Choose the deletion mechanism according to lifecycle ownership and database responsibilities:
- Configure JPA removal with cascade = {CascadeType.PERSIST, CascadeType.REMOVE}; deleting an Item through a repository or EntityManager removes its loaded Bid entities. section 8.3.3
- Expect entity-level cascading to load the collection and issue individual deletes, which can be less efficient than one SQL DELETE. section 8.3.3
- Use orphanRemoval = true when removing a Bid from the Item collection should delete that orphan, not merely when deleting the Item. section 8.3.3
Cascade Item removal
@OneToMany(mappedBy = "item", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) private Set<Bid> bids = new HashSet<>(); itemRepository.delete(item);


