I am using Hibernate as my ORM. I need to cache a static Table(Constant Table). I make a REST Call to my backend which is deployed on Tomcat 7.But for every call query is being fired for the static data even though I have enabled second level cache and set the query to be cached. Below is my configuration.Can any body help me if I am missing something?
hibernate.cfg.xml
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property > name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactor>y</property>
<mapping resource="TableConstants.hbm.xml"/>
<class-cache usage="read-only" class="com.test.hibernateModel.Constants" />
ehcache.xml
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="1800" />
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600">
</cache>
<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="false">
</cache>
<cache name="com.test.hibernateModel.Constants"
maxElementsInMemory="500"
eternal="true"
overflowToDisk="false"
/>
Below is my DAO Code
currentSess=getSessionFactory().openSession();
Criteria consCrit = currentSess.createCriteria(Constants.class);
consCrit.setCacheable(true);
retList=consCrit.list();
I have tried below Code also.But it also make a new query
currentSess=getSessionFactory().openSession();
Query q=currentSess.createQuery("from Constants");
q.setCacheable(true);
return q.list();