If you are using LocalSessionFactoryBean to configure the Hibernate SessionFactory then you can set the entityInterceptor property to an instance of net.sf.hibernate.Interceptor which will be used to construct any Sessions.
I tried this as the following code shows:
Code:
HibernateTemplate hibernateTemplate = getHibernateTemplate();
log.debug("Setting Interceptor");
try {
hibernateTemplate.setEntityInterceptor(new AuditInterceptor());
} catch (HibernateException he) {
log.error(he);
}
log.debug("Done Setting Interceptor");
log.debug("Saving Product");
hibernateTemplate.save(product);
log.debug("Done Saving Product");
I would expect that the onSave method in the AuditInterceptor would be called. It is not. Any idea what I could be doing wrong?
Thanks,
Ethan