[英]Why doesn't interceptor's onLoad() work?
我们有一个基于jboss的系统
persistance.xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="solutions" transaction-type="JTA">
<jta-data-source>java:/mam</jta-data-source>
<class>....</class>
......
<class>....</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.datasource" value="java:/mam"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/solutions"/>
<property name="hibernate.ejb.interceptor"
value="interceptor.AuditAndDeletableCatcherInterceptor"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.use_sql_comments" value="false"/>
<property name="hibernate.generate_statistics" value="false"/>
<property name="hibernate.bytecode.use_reflection_optimizer" value="cglib"/>
<property name="hibernate.dialect" value="com.magenta.componentization.audit.sql.MySQL5CustomDialect"/>
<property name="hibernate.query.substitutions" value="true 1, false 0"/>
<property name="hibernate.connection.provider_class"
value="org.hibernate.connection.DatasourceConnectionProvider"/>
<property name="hibernate.current_session_context_class" value="thread"/>
<property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
</properties>
</persistence-unit>
</persistence>
拦截器代码:
public class AuditAndDeletableCatcherInterceptor extends AuditInterceptor {
DeletableCatcherDeligate deletableCatcherDeligate =
new DeletableCatcherDeligate();
@Override
public boolean onLoad(Object o, Serializable serializable, Object[] objects, String[] strings, Type[] types) {
deletableCatcherDeligate.onLoad(o, serializable, objects, strings, types);
return super.onLoad(o, serializable, objects, strings, types);
}
}
AuditInterceptor扩展了本地休眠的EmptyInterceptor并重载了一些方法,例如onSave(),onFlush(),onPreFlush()
AuditAndDeletableCatcherInterceptor的某些方法可以工作,但是永远不会调用onLoad()。 我究竟做错了什么?
仅当从数据库而不是从缓存中检索对象时,才调用onLoad。 如果对象已被管理,则不调用onLoad。 您可以通过实现PrepareStatement并查看其功能来进行测试。 我要做的就是实现所有的方法和记录它们全部写时的拦截,然后我知道它在做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.