A way to intercept entity update done via HQL/Query<> interface


We had a few entities which were being hard-deleted, and we have updated them to get soft-deleted instead using an “Active” boolean column, for the delete request, we update the “Active” boolean to false via HQL/Query<> interface’s executeUpdate method.

The problem is Hibernate Interceptor doesn’t pick the query executions so that we can audit the entity being deleted, as well as few other things related to that entity. What should be the ideal solution for this ?

Thank you

There are multiple ways you can handle this. Whatever you interceptor is doing, could also be called from the method within which you execute the update query. Alternatively, you could also just switch to fetching the entity, doing the update on it and finally flushing it so that the interceptor is properly called. What are your concerns?