HQL的休眠侦听器/侦听器 [英] Hibernate Interceptor/Listeners for HQL

查看:111
本文介绍了HQL的休眠侦听器/侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Web应用程序,如果httpSession中的用户是一种超级用户(其中​​user.isSuper()返回true),我想阻止hibernate的插入/删除/更新操作.

I have a spring web application where I want to block hibernate's insert/delete/update operation if the user in httpSession is a kind of Super user (where user.isSuper() returns true).

我已经为这些事件实现了侦听器,但是问题是侦听器未针对HQL查询(session.executeUpdate())触发.

I have implemented listener for these events but the problem is that listener is not firing for HQL queries(session.executeUpdate()).

拦截器也有同样的问题.

Same problem is with interceptors as well.

请帮助.

推荐答案

尝试以下代码,而不是session.executeUpdate():-

Try this following code instead of session.executeUpdate() :-

  getSessionFactory().getCurrentSession().setFlushMode(FlushMode.NEVER);
  getSessionFactory().getCurrentSession().close()

这篇关于HQL的休眠侦听器/侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆