Issue
What is Hibernate's EventType that I can listen to when an flush dirty occurs(an update of a managed entity without a call for persist(), for instance)?
I've looked at the docs but didn't found one that is triggered in this situation href="https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/event/spi/EventType.html" rel="nofollow">https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/event/spi/EventType.html
I've found this issue that maybe is exactly what I want, but it's still open https://hibernate.atlassian.net/browse/HHH-8042
I want to get this event to add some kind of logging (and automatically updating the updatedAt column). I think I can do the same using an Interceptor.onFlushDirty, but it looks uglier.
Solution
There are multiple flush event listeners:
DefaultFlushEntityEventListener
DefaultFlushEventListener
DefaultAutoFlushEventListener
and each of those has its own way of verifying if the session is dirty. None of them provides you with an extension point for the "dirty" flush update.
So you have two options:
- You can use the
Interceptor.onFlushDirty
- You can use the
PostUpdate
annotation to add some update time logic.
Answered By - Vlad Mihalcea
Answer Checked By - Pedro (JavaFixing Volunteer)