HQL查询是否总是碰到数据库并得到结果? [英] Does HQL query always hit database and get results?

查看:148
本文介绍了HQL查询是否总是碰到数据库并得到结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过hibernate和情况何时使用 Criteria vs HQL ,我的理解是,在Hibernate中,每当我们通过 Criteria 或 HQL 在两个实例中,hibernate会得到结果集并放入内存,然后当我们再次调用该查询时,数据将从内存而不是点击该数据库,我的理解是正确的吗?

另外,正如您从下面提到的评论和问题中所看到的那样,有人建议Hibernate Criteria会从会话中获取数据并且HQL总是会到达数据库,因此任何数量的对HQL查询的多次调用都会到达数据库,如果是这种情况,那么 HQL 会导致更多问题而不是解决问题。

请告诉你,这与情况有点混淆。



参考问题

解决方案


$取决于您正在制作什么类型的查询和缓存设置。 b $ b Hibernate有三种缓存:会话缓存,查询缓存和二级缓存。会话缓存始终打开,但另外两个可以禁用。



通常缓存不是支持HQL的Criteria API的理由,反之亦然。他们大多只是基本上相同的不同接口。



请参阅 http://www.javalobby.org/java/forums/t48846.html http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html


I was going through hibernate and situations when to use Criteria vs HQL and my understanding is that with Hibernate, everytime when we are querying database either by Criteria or HQL in both instances hibernate would get result set and put in memory and then when we call that query again, data would be fetched from memory rather then hitting that database, is my understanding correct?

Also as you can see from comments to question mentioned below, it was suggested that Hibernate Criteria would get data from session and HQL would always go and hit database and so any number of multiple calls to HQL query will go and hit database and if this is the case then HQL causes more problems than solving.

Kindly advise on this as am little bit confused with the situation.

Reference to question

解决方案

It depends on what kind of queries you are making and about your cache settings.

Hibernate has three kind of caches: session cache, query cache and 2nd level cache. Session cache is always on but the other two can be disabled.

Usually the caching is not the reason to favor Criteria API over HQL or vice versa. They are mostly just different interfaces for essentially the same thing.

See http://www.javalobby.org/java/forums/t48846.html and http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html

这篇关于HQL查询是否总是碰到数据库并得到结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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