使用nolock的Java Hibernate HQL查询 [英] Java Hibernate HQL queries with nolock

查看:289
本文介绍了使用nolock的Java Hibernate HQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以运行这些查询,就好像我向他们添加了(NOLOCK)提示一样?

解决方案

如果你真的需要这个,然后你想做一些事情:

  session.connection()。setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); 

与nolock相同。

在你这样做之前,如果你想做一个肮脏的阅读,真的认真思考。大多数时候,人们这样做是因为这是他们一直以来所做的,而不是因为这是正确的事情。特别是,这不适用于缓存。



其实,这个主题会涉及一些问题。在决定之前仔细阅读。

Is there a way to run these queries as if I added a (NOLOCK) hint to them?

解决方案

If you really need this, then you want to do something like:

session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);

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.

这篇关于使用nolock的Java Hibernate HQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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