Hibernate Interceptor



Interceptor Interface provides methods which can be called at different stages to perform some
required tasks.
Interceptor methods are callbacks from the session to the application, allowing the application to
inspect and/or manipulate properties of a persistent object before it is saved, updated, deleted
or loaded.
Hibernate Interceptor gives us total control over how an object will look to both the application
and the database.
To build/use an interceptor we can either implement Interceptor interface directly or extend EmptyInterceptor class .

Following are some of the methods available within the Interceptor interface:
Method and Description
findDirty()
This method is be called when the flush() method is called on a Session object.

instantiate()
This method is called when a persisted class is instantiated.

isUnsaved()
This method is called when an object is passed to the saveOrUpdate() method

onDelete()
This method is called before an object is deleted. When object is not deleted into database yet.

onFlushDirty()
This method is called when Hibernate detects that an object is dirty (ie. have been changed) during
a flush i.e. update operation.

onLoad()
This method is called before an object is initialized.

onSave()
This method is called before an object is saved. When object is not save into database yet.

postFlush()
This method is called after a flush has occurred and an object has been updated in memory.
Called after the saved, updated or deleted objects are committed to database.

preFlush()
This method is called before a flush.
Called before the saved, updated or deleted objects are committed to database
Read me : Friends There are also more methods available