Using hibernate 2nd level cache or query cache for lazy fetch queries

我的未来我决定 提交于 2019-12-13 16:17:40

问题


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.

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

<cache usage="read-write"/>

sub-element.

The following properties are defined :

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

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.

Is there a configuration to perform to do so ?


回答1:


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/en-US/html_single/#performance-cache-mapping



来源:https://stackoverflow.com/questions/10350794/using-hibernate-2nd-level-cache-or-query-cache-for-lazy-fetch-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!