Hi,
I'm trying to access the database from Hibernate Interceptor (I need to audit only specific objects that are defined in a different table) and the access is impassable (I get exceptions). Is there a way to access database in interceptor?
My AuditTrailInterceptor is:
public class AuditTrailInterceptor extends EmptyInterceptor {
public boolean onSave(Object entity, Serializable id, Object[] state, String[]
propertyNames, Type[] types) {
AuditTrailService serviceComp = (AuditTrailService) SpringBeanFinder
.findBean(SpringBeanFinder.AUDIT_SERVICE);
serviceComp.getObjectAuditCompanies(theCompany)
return false;
}
}
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public Collection<ObjectAuditCompany> getObjectAuditCompanies(Company company){
return objectAuditCompanyDAO.findByQuery("from " + objectAuditCompanyDAO.getPersistentClass().getName() + " where company=? ", company);
}
The AuditTrailInterceptor defined in the applicationContext.xml as a property
<bean id="onboardSessionFactory" parent="sessionFactory">
<property name="entityInterceptor">
<bean class="com.mycompany.daoimpl.AuditTrailInterceptor" />
</property>
</bean>
Thanks!