升级到 Hibernate 5 后 Hibernate Interceptor 不工作
Hibernate Interceptor not working after upgrading to Hibernate 5
早些时候,我的拦截器代码在 Hibernate 3 上运行良好。在我升级到 Hibernate 5 并进行必要的更改后,回调方法(如 onSave 和 onFlushDirty)停止工作。
关于库更改,我将 Hibernate 3 jar 以下替换为 Hibernate 5 jar。
替换了 Hibernate 3 jar-
- dom4j.jar
- hibernate-core-4.3.5.Final.jar
- hibernate-jpa-2.1-api-1.0.0.Final.jar
- jboss-logging.jar
添加了 Hibernate 5 jar-
- byte-buddy-1.9.5.jar
- 同学-1.3.4.jar
- dom4j-2.1.1.jar
- hibernate-commons-annotations-5.1.0.Final.jar
- hibernate-core-5.4.1.Final.jar
- javax.persistence-api-2.2.jar
- javax.transaction.jar
- jboss-logging-3.3.2.Final.jar
下面是我的拦截器代码-
public class CustomInterceptor extends EmptyInterceptor {
@Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
System.out.println("onFlushDirty called");
return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
System.out.println("onSavecalled");
return super.onSave(entity, id, state, propertyNames, types);
}
}
如果有人能指出我遗漏的地方或我需要做的任何更正,那将非常有帮助。
Please Note- Entire Application is working smoothly except that Interceptor Callback methods are not getting called.
能否请您尝试以下操作:
Session session = sessionFactory.withOptions()
.interceptor(new CustomInterceptor())
.openSession();
早些时候,我的拦截器代码在 Hibernate 3 上运行良好。在我升级到 Hibernate 5 并进行必要的更改后,回调方法(如 onSave 和 onFlushDirty)停止工作。
关于库更改,我将 Hibernate 3 jar 以下替换为 Hibernate 5 jar。
替换了 Hibernate 3 jar-
- dom4j.jar
- hibernate-core-4.3.5.Final.jar
- hibernate-jpa-2.1-api-1.0.0.Final.jar
- jboss-logging.jar
添加了 Hibernate 5 jar-
- byte-buddy-1.9.5.jar
- 同学-1.3.4.jar
- dom4j-2.1.1.jar
- hibernate-commons-annotations-5.1.0.Final.jar
- hibernate-core-5.4.1.Final.jar
- javax.persistence-api-2.2.jar
- javax.transaction.jar
- jboss-logging-3.3.2.Final.jar
下面是我的拦截器代码-
public class CustomInterceptor extends EmptyInterceptor {
@Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
System.out.println("onFlushDirty called");
return super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
System.out.println("onSavecalled");
return super.onSave(entity, id, state, propertyNames, types);
}
}
如果有人能指出我遗漏的地方或我需要做的任何更正,那将非常有帮助。
Please Note- Entire Application is working smoothly except that Interceptor Callback methods are not getting called.
能否请您尝试以下操作:
Session session = sessionFactory.withOptions()
.interceptor(new CustomInterceptor())
.openSession();