Hibernate provides full control of an object's states in its life cycle, allowing you to define custom behaviors when the object's state changes. Hibernate can do this thanks to interceptors and listeners. An interceptor is an old mechanism used by Hibernate 2.x. Hibernate 3 introduced the event/listener model instead, but has not removed support for interceptors. Although any interceptor lets you define custom behaviors for all object states, listeners are used at a particular state of an object. To define an interceptor, first implement the
Interceptor interface and override the appropriate methods, and then apply it to the
Session object. Notice that the implemented interceptor cannot be declared declaratively through ...