farzad wrote:
There are two things. First you have to define a cache region for this query and configure that cache region in your cache provider to be eternal or something with a long life span. Second if hibernate detects an update in any entity involved in that query, it will throw away the results for that query so a database hit is an expected behaviour.
Farzad-
Thanks for your quick reply. I changed eternal from false to true in the following ehcache.xml configuration and it worked.The data in the table never changes, i'm wondering why hibernate discard the query cache?
<cache name="com.MyClass"
maxElementsInMemory="100"
eternal="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="36000"
overflowToDisk="false"
/>
I read in Hibernate in Action book that there are three types of cache region : default, named and timestamp. It further says that the query cache result is stale or not is decided by timpestamp cache region. I did not find any example how to disable/enable/configure timestamp cache (UpdateTimeStampCache is the class). Do you have any example configuration for that? Also what is the difference between timeToIdleSeconds and timeToLiveSeconds ? With eternal=false and timeToIdleSeconds=1800, should it not cache the query for 30 minutes at least?