Interceptors and listeners

Interceptors are used to mainly intercept a save or flush. To define a Interceptor we have to implement the

Interceptor interface.However extending the EmptyInterceptor class helps as it gives you the basic implementations of the needed functions.

Session:

the session used by the interceptor should be independent of the session on which the interceptor is working on.

Adding Interceptors

On Session:

    • The Interceptor need not be thread safe.

    • The interceptor is added to the sessions as [sessionFactory.openSession(interceptor)]

On SessionFactory:

    • The Interceptor needs to be thread safe as it works with instance objects.

    • The interceptor is added using the Configuration before the sessionFactory is build.