`

Hibernate之查询缓存(The Query Cache)

阅读更多

查询的结果集也可以被缓存。只有当经常使用同样的参数进行查询时,这才会有些用处。

 

   Query Cache中保存了之间查询操作执行过的Select SQL,以及由此查存产生的查询结果集(包括查询对象的类型和id);之后,如果再次发出查询请求时,Hibernate会根据查询的SQL从Query Cahce中检索,如果此SQL曾经执行过,则取出对应这个SQL所检索出来的结果集,再根据这个结果集中的对象类型和id,从缓存中取出对应的实体对象返回;

 

   Query Cache中缓存的SQL及结果集并非一直存在,当Hibernate发现此SQL对应的库发生变动(Update/Delete/Insert),会自动将Query Cahce中对应表的SQL缓存废除。因此,Query Cahce只在特定的情况下使用;

  • 完全的Select SQL重复执行
  • 在两次查询之间,此Select SQL对应的表没有发生变动

但是,以上的两种情况限制比较严格,所以hibernate默认的是将其关闭,需要使用时候可以通过配置属性将其打开:

hibernate.cache.use_query_cache true

 之后必须在Query的查询执行之前,将Query.Cacheable设为true:

Query query = session.createQuery(hql);
query.setCacheable(true);
 

 

 

分享到:
评论

相关推荐

    7:Hibernate查询缓存及实现.PPT

    7:Hibernate查询缓存Query Cache及实现

    Hibernate_二级缓存总结

    QueryCache 用来缓存查询语句 , 及查询结果集中对象的 Identifier 与 Type. 当再次使用已缓存的 Query 时 , 就可以通过对象的 Identifier 与 Type 在 SECOND LEVEL CACHE 中查找实际的对象 . 对于查询缓存来说,...

    hibernate 3中的缓存小结

    为此,Hibernate提供了针对条件查询的Query Cache。 2.3.2. 什么样的数据适合存放到第二级缓存中? 1 很少被修改的数据 2 不是很重要的数据,允许出现偶尔并发的数据 3 不会被并发访问的数据 4 参考数据,指的是供应...

    hibernate4.0使用二级缓存jar包

    <property name="hibernate.cache.use_query_cache">true <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider 4.0配置如下: <property name="hibernate.cache.use_second_level_cache...

    hibernate二级缓存

    Hibernate二级缓存 在一个数据库系统中,如果缓存设置的... hibernate.cache.use_query_cache必须配置,如果想缓存使用findall()、list()、Iterator()、createCriteria()、 createQuery()等方法获得的数据结果集。

    grails-redis-hibernate-cache:Grails 与 Redis 的集成作为 Hibernate 二级缓存的后端

    Grails Redis Hibernate 二级缓存 这个插件简化了 Grails Hibernate 2nd Level 缓存和 Redis 之间的集成。 安装 要安装,您需要将插件添加到 BuildConfig.groovy 中 compile " :redis-hibernate-cache:1.0 " 还有这...

    Spring 整合 Hibernate 时启用二级缓存实例详解

    Spring 整合 Hibernate 时启用二级缓存实例详解 写在前面:  1. 本例使用 Hibernate3 + Spring3;  2. 本例的查询使用了 HibernateTemplate;...<prop key=hibernate.cache.use_query_cache>true <!-

    hibernate3.2中文文档(chm格式)

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    HibernateAPI中文版.chm

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    Hibernate+中文文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    Hibernate 中文 html 帮助文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    hibernate 教程

    查询缓存(Query Cache) 15. 工具箱指南 15.1. Schema 生成器(Schema Generation) 15.1.1. 对schema定制化(Customizing the schema) 15.1.2. 运行该工具 15.1.3. 属性(Properties) 15.1.4. 使用...

    hibernate 体系结构与配置 参考文档(html)

    二级缓存与查询缓存 3.4.5. 查询语言中的替换 3.4.6. Hibernate的统计(statistics)机制 3.5. 日志 3.6. 实现NamingStrategy 3.7. XML配置文件 3.8. J2EE应用程序服务器的集成 3.8.1. 事务策略配置 3.8.2. ...

    Hibernate中文详细学习文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    最全Hibernate 参考文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    Hibernate教程

    20.4. 查询缓存(The Query Cache) 20.5. 理解集合性能(Understanding Collection performance) 20.5.1. 分类(Taxonomy) 20.5.2. Lists, maps 和sets用于更新效率最高 20.5.3. Bag和list是反向集合类中效率...

    Hibernate参考文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

    hibernate

    查询缓存(Query Cache) 15. 工具箱指南 15.1. Schema 生成器(Schema Generation) 15.1.1. 对schema定制化(Customizing the schema) 15.1.2. 运行该工具 15.1.3. 属性(Properties) 15.1.4. 使用...

    Hibernate3+中文参考文档

    19.4. 查询缓存(The Query Cache) 19.5. 理解集合性能(Understanding Collection performance) 19.5.1. 分类(Taxonomy) 19.5.2. Lists, maps 和sets用于更新效率最高 19.5.3. Bag和list是反向集合类中效率...

Global site tag (gtag.js) - Google Analytics