How to cascade DELETE with Spring and Hibernate events

Introduction In this article, we are going to see how we can cascade the DELETE operation for unidirectional associations with Spring Data JPA and Hibernate events. Using Hibernate events to achieve this goal is an alternative to the bulk DELETE statement strategy, as it allows us to cascade the delete operation from a parent entity to its children when we cannot use the CascadeType mechanism.

How to cascade DELETE unidirectional associations with Spring Data JPA

Introduction In this article, we are going to see how to cascade DELETE the unidirectional associations with Spring Data JPA when we cannot rely on the CascadeType mechanism that propagates state transitions from parent to child entities.

Soft delete and JPA version property

Introduction In this article, we are going to see how we can implement a soft delete mechanism when the JPA entity features a version property. If you are not using a version property for optimistic locking, then you can implement the soft delete strategy, as explained in this article.

The best way to soft delete with Hibernate

Introduction Each database application is unique. While most of the time, deleting a record is the best approach, there are times when the application requirements demand that database records should never be physically deleted. So who uses this technique? For instance, StackOverflow does it for all Posts (e.g. Questions and Answers). The StackOverflow Posts table has a ClosedDate column which acts as a soft delete mechanism since it hides an Answer for all users who have less than 10k reputation. If you’re using Oracle, you can take advantage of its Flashback capabilities,… Read More

How to batch DELETE statements with Hibernate

Introduction In my previous post, I explained the Hibernate configurations required for batching INSERT and UPDATE statements. This post will continue this topic with DELETE statements batching. Domain model entities We’ll start with the following entity model: