Spring hibernate EHCache dont work
Folks,
I am trying to implement readOnly query cache within spring framework using hibernate and EHCache.
I have configured show_sql = true.
Now when First time when I invoke query, I sees hibernate generating query.
But next time I expect hibernate should return result from cache. But every time I see it generating query repeatively and returning result from database taking same amount of time.
Any idea please suggest. This is quite urgent.
This is my hibernate config
=======================
<bean id="dareSessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource" ref="dareOracleDataSource"/>
<property name="mappingResources">
<list>
<value>SourceSystem.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle9Dia lect
hibernate.show_sql=true
hibernate.cache.provider_class=org.hibernate.cache .EhCacheProvider
hibernate.hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
</value>
</property>
<property name="entityCacheStrategies">
<value>
com.dare.beans.SourceSystem=read-only
</value>
</property>
</bean>
<bean id="cacheDataDAO" class="com.dare.dao.CacheDataDAOSupport" lazy-init="false">
<property name="sessionFactory" ref="dareSessionFactory"/>
</bean>
================================================
This is my EHCache Config
================================================
<ehcache><defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>
<cache name="com.dare.beans.SourceSystem"
maxElementsInMemory="20"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
/></ehcache>
=================================================
Now this is my Object-DB mapping file SourceSystem.hbm.xml
================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.dare.beans" default-lazy="false">
<class name="SourceSystem" table="SOURCE_SYSTEM"
dynamic-update="false">
<meta attribute="class-description">
Source System business object. @author Shivnarayan
</meta>
<cache usage="read-only" />
<id name="sourceSystemId" type="string" unsaved-value="null">
<column name="SOURCE_SYSTEM_ID" sql-type="char(32)"
not-null="true" />
<generator class="native" />
</id>
<property column="SYSTEM_ACRONYM" name="systemAcronym" />
<property column="EXCEPTION_PROCESSING_METHOD"
name="exceptionMethod" />
<property column="BUSINESS_AREA" name="businessArea" />
</class>
</hibernate-mapping>
============================================
My DAO Class :
public class CacheDataDAOSupport implements CacheDataDAO {
private HibernateTemplate hibernateTemplate;
public void setSessionFactory(SessionFactory sessionFactory) {
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
this.hibernateTemplate.setCacheQueries(true);
}
public List<SourceSystem> getSendingSystemIdentifier() throws DataAccessException {
return this.hibernateTemplate.loadAll(SourceSystem.class) ;
}
}
==========================================
Please help.