Hello,
In my application using Hibernate, spring and struts, I put ehcache for my entites and my queries. the problem I have is that my entities and my queries are not keep in cache for the time i specified in my eh cache configuration file. Since timeToIdleSeconds is the number of seconds that an Element should live since it was last used, my queries, after an use must be kept during one hour? right? But, when I call a method of DAO to load entities from the database, the first time it does it. When I recall this method after 5 seconds or 10, it use the cache, but when I call it after 2 or 3 three minutes, it performs the query in database. I don't understand why
this is my ehcache configuration file :
Code:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<defaultCache maxElementsInMemory="100000" eternal="false"
timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" />
<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="true">
</cache>
this is the method of my DAO that I call
Code:
@Override
public List<Pays> listePays(long idRegion) {
Criteria criteria = super.getSession().createCriteria(Pays.class);
criteria.createAlias("region", "r");
criteria.setFetchMode("pc", FetchMode.JOIN);
criteria.setFetchMode("ps", FetchMode.JOIN);
criteria.setFetchMode("kf", FetchMode.JOIN);
criteria.add(Restrictions.eq("r.id", idRegion));
criteria.setCacheable(true);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return criteria.list();
}
Any help is welcome. thanks in advance