My Application uses FlushMode.AUTO
.
For a particular service method call I want to change Hibernate Session.FlushMode
to FlushMode.COMMIT
and revert back to FlushMode.AUTO
when the method completes.
Question:- Are there any problem/dangers of changing FlushMode during the session?
Reason for changing FlushMode during a session:-
I am using Hibernate Interceptor Approach (onFlushDirty
) for auditing changes.
With FlushMode.AUTO ,Multiple Session Flushes are occuring(behaviour of FlushMode.AUTO
) . So consequently onFlushDirty
is being invoked multiple times leading to duplicate audit.
I workaround above issue by changing FlushMode
to COMMIT
in the method where i am expecting auditing to happen.