Events

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 load, save, merge, lock, and flush. For a complete list of events in Hibernate, you should look at the JavaDoc for org.hibernate.event.spi.EventType.

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.

Event listener

Hibernate defines the event contract using the listener interfaces (refer to org.hibernate.event.spi) and it ...

Get Mastering Hibernate now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.