title: Spring+Hibernate+Ehcache make query_cache never expire
body: <p>I'm trying, in my Spring(3.2)+Hibernate(4.2) application, to <strong>make query_cache never expire</strong></p>
  
  <p>I tried the following configurations, the cache is working but after 120 seconds, my cacheable query hit the database, even if <strong>timeToIdleSeconds</strong> and <strong>timeToLiveSeconds</strong> are set to a value greater then 120</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
       updateCheck="false"&gt;  
  
   &lt;defaultCache
      maxElementsInMemory="10000"
      eternal="false"
      timeToIdleSeconds="1800"
      timeToLiveSeconds="3600"
      overflowToDisk="true"
      maxElementsOnDisk="10000000"
      diskPersistent="false"
      diskExpiryThreadIntervalSeconds="1800"  /&gt;
  
  &lt;cache name="org.hibernate.cache.StandardQueryCache"
      maxEntriesLocalHeap="25"
      eternal="false"
      timeToIdleSeconds="1800"        
      timeToLiveSeconds="3600"&gt;
          &lt;persistence strategy="localTempSwap"/&gt;
  &lt;/cache&gt;
  
  &lt;cache name="org.hibernate.cache.UpdateTimestampsCache"
      maxEntriesLocalHeap="5000"
      timeToIdleSeconds="1800"
      timeToLiveSeconds="3600"
      eternal="false"&gt;
          &lt;persistence strategy="localTempSwap" /&gt;
  &lt;/cache&gt;
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>I included Ehcache using:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
          &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt;
          &lt;version&gt;2.6.6&lt;/version&gt;
      &lt;/dependency&gt;        
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
          &lt;version&gt;4.2.6.Final&lt;/version&gt;
      &lt;/dependency&gt;     
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.6.1&lt;/version&gt;
      &lt;/dependency&gt; 
  </code></pre>
  
  <p>Note: I have already tried with: <strong>timeToIdleSeconds="0" and timeToLiveSeconds="0"</strong> but with no luck, I get the same behavior, 120 seconds and the cache get cleared. Here is the full log:</p>
  
  <pre><code>21:52:11,128 DEBUG StandardQueryCache:131 - Checking cached query results in region: org.hibernate.cache.internal.StandardQueryCache
  
  21:52:11,129 DEBUG EhcacheGeneralDataRegion:69 - key: sql: select this_.townID as townID1_33_1_, this_.name as name2_33_1_, this_.zip_code as code_pos3_33_1_, this_.regionID as regionID4_33_1_, region2_.regionId as regionId1_27_0_, region2_.name as name2_27_0_ from town this_ left outer join region region2_ on this_.regionID=region2_.regionId; parameters: ; transformer: org.hibernate.transform.CacheableResultTransformer@13a525
  
  21:52:11,129 DEBUG EhcacheGeneralDataRegion:76 - Element for key sql: select this_.townID as townID1_33_1_, this_.name as name2_33_1_, this_.zip_code as code_pos3_33_1_, this_.regionID as regionID4_33_1_, region2_.regionId as regionId1_27_0_, region2_.name as name2_27_0_ from town this_ left outer join region region2_ on this_.regionID=region2_.regionId; parameters: ; transformer: org.hibernate.transform.CacheableResultTransformer@13a525 is null
  
  21:52:11,129 DEBUG StandardQueryCache:137 - Query results were not found in cache
  
  Hibernate: select this_.townID as townID1_33_1_, this_.name as name2_33_1_, this_.zip_code as code_pos3_33_1_, this_.regionID as regionID4_33_1_, region2_.regionId as regionId1_27_0_, region2_.name as name2_27_0_ from town this_ left outer join region region2_ on this_.regionID=region2_.regionId
  
  21:52:11,137 DEBUG StandardQueryCache:104 - Caching query results in region: org.hibernate.cache.internal.StandardQueryCache; timestamp=5657678361137154
  
  21:52:11,138 DEBUG EhcacheGeneralDataRegion:100 - key: sql: select this_.townID as townID1_33_1_, this_.name as name2_33_1_, this_.zip_code as code_pos3_33_1_, this_.regionID as regionID4_33_1_, region2_.regionId as regionId1_27_0_, region2_.name as name2_27_0_ from town this_ left outer join region region2_ on this_.regionID=region2_.regionId; parameters: ; transformer: org.hibernate.transform.CacheableResultTransformer@13a525 value: [5657678361137154, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
  </code></pre>
  
  <p>I activated the 2nd level cache and the query_cache using:</p>
  
  <pre><code>&lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt;
  &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt; 
  &lt;prop key="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory&lt;/prop&gt;                
  &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;/ehcache.xml&lt;/prop&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My query is generated using the Criteria API:</p>
  
  <pre><code>public List&lt;Town&gt; readAll() {
    Criteria crit = getCurrentSession().createCriteria(Town.class);
    crit.setCacheable(true);
    return crit.list();
  }
  </code></pre>
  
  <p>I'm using read-write as CacheConcurrencyStrategy. So I My entity Town I have this:</p>
  
  <pre><code>&lt;cache usage="read-write" /&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I just saw this when starting my application:</p>
  
  <pre><code>22:10:45,570  WARN ConfigurationFactory:136 - No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/work/Catalina/localhost/projet/loader/ehcache-failsafe.xml
  22:00:49,812  INFO UpdateTimestampsCache:61 - HHH000250: Starting update timestamps cache at region: org.hibernate.cache.spi.UpdateTimestampsCache
  22:00:49,818  WARN AbstractEhcacheRegionFactory:180 - HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults.
  </code></pre>
  
  <p>I think that the configurations I made in WEB-INF/ehcache.xml are not considered
  what's wrong? is it the wrong place?</p>