Hello,
Iam kind of new to Hibernate, so trying to see whats wrong with the configuration/code i have.
If i execute the query in a loop the results are fine, Iam getting all the values from cache. But when i sleep for 2 min or so and execute its executing the sqls and not getting from the cache.
Following are some of the cache logs.
15:32:24 DEBUG cache.StandardQueryCache - checking cached query results in region: UserQueryCacheRegion
15:32:24 DEBUG cache.StandardQueryCache - query results were not found in cache
15:32:25 DEBUG cache.StandardQueryCache - caching query results in region: UserQueryCacheRegion
I defined by own Query Cache region: (iam using EHcache)
<cache
name="UserQueryCacheRegion"
maxElementsInMemory="10000"
eternal="true"
timeToIdleSeconds="3600" // i tried with value 0 also
timeToLiveSeconds="3600" // i tried with value 0 also
overflowToDisk="true"
/>
The eternal is set to true and also the idle or live seconds is set to an hour. Heres my cache props:
<property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
My code is like:
try {
HbSessionUtil.getSession(); //open session
String hqlQuery = "from User as user where user.userPriv.privKey=?"
Query query = session.createQuery(hqlQuery);
query.setString(1, "abc");
query.setCacheable(true);
query.setCacheRegion(HbConstants.USER_QUERY_CACHE_REGION);
...........
LogUtil.debug(CLASSNAME,
"Time taken for Hibernate transaction: "
+ (System.currentTimeMillis() - startMs));
} catch (Exception excep) {
LogUtil.debug(CLASSNAME, "Hibernate error while getting Test", excep);
throw new HbException(excep);
} finally {
HbSessionUtil.closeSession();//close session
}
I would really appreciate your help.
|