Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate EmptyInterceptor更改查询类型_Java_Hibernate - Fatal编程技术网

Java Hibernate EmptyInterceptor更改查询类型

Java Hibernate EmptyInterceptor更改查询类型,java,hibernate,Java,Hibernate,当我更新一个实体时,我想自动更新一个修改字段 为此,我使用EmptyInterceptor和以下方法: public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {} public void onDelete(Object entity, Serializabl

当我更新一个实体时,我想自动更新一个修改字段

为此,我使用EmptyInterceptor和以下方法:

 public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {}
 public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {...}
我有我所期待的

现在,当我删除一个实体时,我想自动更新一个deletition_tms字段,我想要一个更新查询,而不是删除查询

我尝试通过以下方法来实现:

 public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {}
 public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {...}
我可以在deletation_tms字段中设置一个新值,但当然,实体在删除后会被删除。我不知道是否有办法将删除查询“转换”为更新查询

你能帮我吗

我正在使用Hibernate4


您的应用程序中有DAO层吗?只需在hibernate会话上实现delete方法调用
update
。我有一个DAO层,但这个解决方案不适合我。如果我有一个实体(名为A)和其他实体(名为B)的列表,我在删除B-->A时不会调用删除方法。删除(B)您的意思是B中包含A,当您删除B时,它只对B有效,而B中的A将保留。是吗?不,对不起。A包含B。当我执行A.remove(B)时,我会看到查询“deletefromb…”。在这种情况下,我不会在DAO层中使用delete方法。出于这个原因,我想使用一个拦截器(或类似的东西)来更新字段deletation_tms,并将delete转换为update