• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is Interceptors?

 
Ranch Hand
Posts: 80
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic