使用Hibernate 2级缓存或查询缓存进行延迟获取查询 [英] Using hibernate 2nd level cache or query cache for lazy fetch queries

查看:74
本文介绍了使用Hibernate 2级缓存或查询缓存进行延迟获取查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ehcache 2.5.2库成功将hibernate 3.6.2设置为使用二级缓存.

I successfully setup hibernate 3.6.2 to use second level cache, using the ehcache 2.5.2 library.

我在日志和统计信息中看到,实体填充了二级缓存,并且缓存了我要缓存的查询.

I can see in logs and statistics that entities populate second level caches and that the queries that I want to be cacheable are cached.

当我在hbm.xml文件中使用XML配置时,认为的类具有一个

As I use XML configuration in hbm.xml files, considered classes have a

<cache usage="read-write"/>

子元素.

定义了以下属性:

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=true

但是,hibernate不会缓存它生成的用于执行实体或集合的延迟加载的查询.我可以在postgresql日志中看到它们以相同的参数一遍又一遍地执行.

However, hibernate does not cache the queries it generates to perform lazy loading of entities or collections. I can see them executed over and over, with the same parameters, in postgresql logs.

是否需要执行配置?

推荐答案

您只需要确保使用@Cache注释映射了您的类和关系.

You just need to make sure that your classes and relatons are mapped using @Cache annotation.

您可以在此处了解更多信息:

You can read more about it here:

http://docs .jboss.org/hibernate/core/3.6/reference/zh-CN/html_single/#performance-cache-mapping

这篇关于使用Hibernate 2级缓存或查询缓存进行延迟获取查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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