我正在尝试从 Hibernate Interceptor 访问数据库(我只需要审核在不同表中定义的特定对象)并且无法访问(我得到异常)。有没有办法在拦截器中访问数据库?
我的 AuditTrailInterceptor 是:
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);
}
在 applicationContext.xml 中定义为属性的 AuditTrailInterceptor
<bean id="onboardSessionFactory" parent="sessionFactory">
<property name="entityInterceptor">
<bean class="com.mycompany.daoimpl.AuditTrailInterceptor" />
</property>
</bean>
谢谢!