下面我有以下配置:我Hibernate的攔截器不工作
<bean id="myHibernateInterceptor" class="com.foo.interceptor.MyHibernateInterceptor" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="entityInterceptor" ref="myHibernateInterceptor"/>
</bean>
但我的休眠攔截從不開火。任何線索?
這裏是攔截代碼:
public class MyHibernateInterceptor extends EmptyInterceptor {
@Override
public boolean onFlushDirty(final Object entity, final Serializable id,
final Object[] currentState, final Object[] previousState,
final String[] propertyNames, final Type[] types) {
setValue(currentState, propertyNames, "createdOn", new Date());
return true;
}
}
看起來一見鍾情。你的攔截器怎麼樣 - 你擴展EmptyInterceptor嗎?如果是的話,你會覆蓋哪些方法?也許你可以展示更多的代碼。 – jeha