Hi All,
After much googling and combing thru the Hibernate forum, I seek your help on following issue:
Context:
I am trying to set-up L2 caching mechanism using EhCache as the cache provider on Hibernate3.2. In order to do so, I have the done the following configuration:
a) Enabled caching in hibernate configuration file:
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
b) Tagged relevant hbm.xml files with <cache> tag
<cache usage="read-only"/>
c) Configured default cache regions in ehcache.xml
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
/>
</ehcache>
Issue:
Now when I tried to use HQL to load objects, the objects though getting cached in L2 are not getting fetched from L2 on subsequent hits. I enabled the Second-Level Statistics(pasted below) to decipher the same
First Hit using HQL:
Statistics[start time=1180365059200,sessions opened=1,sessions closed=0,transactions=0,successful transactions=0,optimistic lock failures=0,flushes=0,connections obtained=38,statements prepared=38,statements closed=38,second level cache puts=9,second level cache hits=0,second level cache misses=0,entities loaded=64,entities updated=0,entities inserted=0,entities deleted=0,entities fetched=27,collections loaded=9,collections updated=0,collections removed=0,collections recreated=0,collections fetched=9,queries executed to database=2,query cache puts=1,query cache hits=0,query cache misses=1,max query time=265]
Second Hit using HQL:
Statistics[start time=1180365059200,sessions opened=2,sessions closed=1,transactions=0,successful transactions=0,optimistic lock failures=0,flushes=0,connections obtained=76,statements prepared=76,statements closed=76,second level cache puts=18,second level cache hits=0,second level cache misses=0,entities loaded=128,entities updated=0,entities inserted=0,entities deleted=0,entities fetched=54,collections loaded=18,collections updated=0,collections removed=0,collections recreated=0,collections fetched=18,queries executed to database=4,query cache puts=2,query cache hits=0,query cache misses=2,max query time=265]
As you can see that on subsequent hits second-level-cache puts doubles-up. Also, I have tried enabling the query cache in the hope of fixing this but to no avail.
However, caching works perfectly if I use session.load() or session.get() instead of HQL.
Any pointers in this regard would be highly appreciated!
Thanks in Advance
-K
|