aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Query Cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Query Cache" Watch "Hibernate Query Cache" New topic
Author

Hibernate Query Cache

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Hi,

I try to setup Hibernate Query Cache, I am using ehcache.

It works in the beginning (i.e. if i execute the same query multiple times,
it does not send the sql commands to mysql everytime).

however, after about 1 minutes, the cache seems expire (i.e. I see hibernate executes sql commmands to the database.


I have the following configuration in my ehcache.xml file. So the query cache should last 2 hours (7200 seconds), I don't understand why my query cache expires so soon.

Thank you for any help.

<defaultCache maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="7200" timeToLiveSeconds="7200" diskPersistent="false" diskExpiryThreadIntervalSeconds="7200"/>
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
- show the code where you create the query
- are there more different queries than the cache size ?

pascal
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If we are talking about the Query Cache, do the parameters of your query change? This will mean the cache needs rebuilt.

However, you mention ehcache, which suggests this might be about Second Level caching, which is nothing to do with Query Caching. In which case, you might want to check that your cache has not become full.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85
Thanks for the help.



No, I am pretty sure that the query only return 1 result.
And I am sure that the query parameters are the same everything i execute the query because I just reloading the same page again and again (which trigger the query with parameters).

I appreciate if anyone can give me some ideas to my problem.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1382
you need to set the hibernate.cache.use_query_cache property in the hibernate.cfg.xml file to true, as follows:

<property name="hibernate.cache.use_query_cache">true</property>

Then, you use the setCacheable() method.

http://www.devx.com/dbzone/Article/29685/1954?pf=true refer this link.

QueryCaching is diffferent from the second level caching.
 
 
subject: Hibernate Query Cache