As discussed in
Chapter 1, Entity and Session, almost every action in the persistence context is translated into an event. This includes events such as
flush. For a complete list of events in Hibernate, you should look at the JavaDoc for
Every event in Hibernate has a corresponding listener that acts when the event is fired. The Hibernate event architecture uses the Service Provider Interface model to discover event listeners. This allows you to plug in your own listener for a certain event. In this section, we will show you how to write event listeners.
Hibernate defines the event contract using the listener interfaces (refer to
org.hibernate.event.spi) and it provides a default implementation for each event (see
org.hibernate.event.internal). Through the service provider interface, you can append additional listeners. Keep in mind that event listeners are considered singletons, so they are not thread-safe...