• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate Query Cache

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"/>
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- show the code where you create the query
- are there more different queries than the cache size ?

pascal
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic