There are a couple of ways you can do this.
1. Push-in refactor the remove()
method
Instead of going all the way to change the entityManager, you can push-in refactor the remove()
method to your entity class and set the active
value to be false
within the method and call merge()
.
Also note that you would need to modify the finders and most other methods to filter the entities which are set to be active=false
.
2. Spring Roo Behaviors Add-on @RooSoftDelete
annotation
You can also use the following Spring Roo addon which enables a soft delete.
It lets you add a new annotation named @RooSoftDelete
which takes care of soft deletion.
Apart from the above, you can also write a custom entity manager factory that would take care of all as well.
Cheers.