使用 nolock 的 Java Hibernate HQL 查询
有没有办法像我向它们添加 (NOLOCK) 提示一样运行这些查询?
Is there a way to run these queries as if I added a (NOLOCK) hint to them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你确实需要这个,那么你想做类似的事情:
这与 nolock 相同。
在此之前,请务必仔细考虑是否要进行脏读。大多数时候,人们这样做是因为这是他们一直在做的事情,而不是因为这是正确的事情。特别是,这对于缓存来说效果不佳。
实际上,此线程稍微探讨了这些问题。决定前请仔细阅读。
If you really need this, then you want to do something like:
which is identical to a nolock.
Before you do that, really think carefully if you want to do a dirty read. Most of the time people do this because it's what they've always done, rather than because it's the right thing to do. In particular, this does not work well with caching.
Actually, this thread goes into the issues a little. Read carefully before deciding.
在最新版本的 Hibernate 中,你必须这样做:
In latest version of Hibernate you have to do it this way:
如果你是原生的,你可以使用“with (nolock)”。这是极端的,但如果替代方案是更改事务隔离级别,您可能宁愿这样做。
请注意,此示例适用于 MSSQL。
You can do the "with (nolock)" if you go native. This is extreme but if the alternative is changing the transaction isolation level, you might rather do this.
Note that this example is for MSSQL.