0
如何輕鬆地在Spring應用程序的applicationContext.xml中掛接Hibernate EmptyInterceptor(審覈攔截器)?如何在Spring的applicationContext.xml中註冊Hibernate空攔截器
不支持註釋,這是一個較舊的Spring應用程序。
我休眠空攔截器是
public class AuditInterceptor extends EmptyInterceptor {
private static final long serialVersionUID = 1L;
@Override
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
// TODO Auto-generated method stub
System.out.println("onDelete intercepted");
super.onDelete(entity, id, state, propertyNames, types);
}
@Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
String[] propertyNames, Type[] types) {
// TODO Auto-generated method stub
System.out.println("onFlushDirty intercepted");
return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
// TODO Auto-generated method stub
System.out.println("onSave intercepted");
return super.onSave(entity, id, state, propertyNames, types);
}
}
的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jdbc.datasource}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.timeout">5000</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.c3p0.acquire_increment">2</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
http://forum.spring.io/forum/spring-projects/data/2323-how-use-use-an-hibernate-interceptor-with-spring – StanislavL