• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is Interceptors?

 
Shahir Deo
Ranch Hand
Posts: 80
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am New to Hibernate , Can I know what is Interceptor interface ? and where it is used and why it is used? and what is dirty checking?
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the object has been changed, it must be saved back to the database. This process continues until the next time the object is needed, and it will be loaded from the persistent store. Interceptor Interface provides methods which can be called at different lifecycle stages to perform some required tasks. These 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 an you do not have to explicitly call them. When the flush() method is called on an entity, the existing state in the database is checked with the entity's state and if there are any changes, it is treated as dirty, which means that an update operation is required at the database end.
To call an interceptor, you need to set it while opening the session or session factory:
HibernateUtil.getSessionFactory().openSession(<interceptor object>)
new Configuration().setInterceptor( <interceptor object> );

It is useful if you are debugging some problem with the state and/or need persistence operation occurrence for audit/logging/security related events.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic