[英]Intercept spring data jpa annotation @Modifying
I want to audit all entity modifications, so I used a class that implements org.hibernate.Interceptor. 我想审核所有实体修改,所以我使用了一个实现org.hibernate.Interceptor的类。 But the onDelete method does not get called if I delete the entity(or entities) using this method:
但是,如果我使用此方法删除一个或多个实体,则不会调用onDelete方法:
@Modifying @Query ("delete from Brand b where b.name= :name") public void deleteAllByName(Param("name") String name);
Is there a way to intercept this kind of queries? 有没有办法拦截这种查询?
PS: Calling the interceptors method before/after every this kind of query is not an option, because there are over 100 cases and probably more will be written. PS:在每种此类查询之前/之后都不能调用拦截器方法,因为有100多种情况,而且可能还会编写更多的情况。
Thanks, Tekin. 谢谢,特金
I found a solution, not a good one, but it will do for now: I overriden the method public String onPrepareStatement(String query)
in the EmptyInterceptor (basic implementation for Interceptor) and checked if the query started with 'insert', 'update' or 'delete'. 我找到了一个解决方案,但不是一个好的解决方案,但现在可以解决:我在EmptyInterceptor(Interceptor的基本实现
public String onPrepareStatement(String query)
中覆盖了public String onPrepareStatement(String query)
,并检查了查询是否以“ insert”,“ update”开头”或“删除”。 I needed to know this because I had to mark an entity as being expired. 我需要知道这一点,因为我必须将一个实体标记为已过期。 Still, if anyone has a better solution please tell me.
不过,如果有人有更好的解决方案,请告诉我。
Thank you. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.