title: Some cached elements are not deleted after cache evictAll()
body: <p>This is a Spring + JPA + Hibernate + EhCache application. I am facing some issues with cache (or I am assuming that is due to cache configuration). I am trying to cache some objects (it works fine, I can see in the cache statistics). The problem is that I want to flush the cache with a button if, for example, I need to update database directly to change some information from an external application.</p>
  
  <p>The ExaminationForm entity is something like:</p>
  
  <pre><code>@Entity
  public class ExaminationForm implements Serializable {
  private static final long serialVersionUID = -7235473414679474757L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "ID", unique = true, nullable = false)
  private Long id;
  
  @Column(nullable = false, length = 150)
  private String name;
  
  // Duration in minutes
  private Integer duration;
  
  //Getters and setters and other stuff... 
  </code></pre>
  
  <p>Of course there are lot of more entities, but are working correctly and therefore obviated in the question. The DAO is more or less like:</p>
  
  <pre><code>@Repository
  public class ExaminationFormDao {
  
  @Override
  @Cacheable(value = "examinations", key = "#id")
  @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
  public ExaminationForm get(Long id) {
      return super.get(id);
  }
  
  @Override
  @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
  public List&lt;EntityClass&gt; getAll() {
      CriteriaQuery&lt;EntityClass&gt; query = getEntityManager().getCriteriaBuilder().createQuery(getEntityClass());
      query.select(query.from(getEntityClass()));
      try {
          return getEntityManager().createQuery(query).getResultList();
      } catch (NoResultException nre) {
          return new ArrayList&lt;EntityClass&gt;();
      }
  }
  
  @Caching(evict = { @CacheEvict(value = "examinations", allEntries = true) })
  public void evictAllCache() {
      getEntityManager().getEntityManagerFactory().getCache().evictAll();
  }
  </code></pre>
  
  <p>In my applicationContext.xml of spring, I define the cache configuration as follows:</p>
  
  <pre><code>&lt;!--  Cache Configuration  --&gt;
  &lt;cache:annotation-driven /&gt;
  &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" /&gt;
  &lt;bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" p:shared="true" /&gt;
  </code></pre>
  
  <p>Hibernate related data only contains connection information and C3P0 variables. Therefore I do not copy here to avoid to much code. </p>
  
  <p>With the ehcache.xml configuration as:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ehcache name="usmocache"&gt;     
  &lt;diskStore path="java.io.tmpdir" /&gt;
  &lt;defaultCache eternal="true" maxElementsInMemory="0"
      overflowToDisk="false" statistics="true" /&gt;
  &lt;cache name="examinations" copyOnRead="true" copyOnWrite="true" 
      maxElementsInMemory="2000" eternal="false"
      timeToIdleSeconds="0" timeToLiveSeconds="1200" overflowToDisk="false"
      diskPersistent="false" memoryStoreEvictionPolicy="LFU" statistics="true" /&gt;
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>There are more data, but I do not want to copy thousands of lines of code to ask this question. If required, I can put more info later.</p>
  
  <p>Check that for evicting all classes I clean the region and also I execute <code>getEntityManager().getEntityManagerFactory().getCache().evictAll();</code> to be sure that is removed. When I press the button I call the evictAllCache() in both DAOs. Probably is not the best approach and is redundant, but I am trying different approach without success. Also <code>getAll()</code> has not any <code>@Cacheable</code> annotation. </p>
  
  <p>The problem is when I access to the getAll method of the DAO. First time, with Hibernate and cache debug set to on I get:</p>
  
  <pre><code>SQL [qtp684428083-26] - select examinatio0_.ID as ID1_12_, examinatio0_.duration as duration2_12_, examinatio0_.name as name3_12_ from examination_form examinatio0_
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([ID1_12_] : [BIGINT]) - [1]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([duration2_12_] : [INTEGER]) - [15]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([name3_12_] : [VARCHAR]) - [Examination1Name]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([ID1_12_] : [BIGINT]) - [2]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([duration2_12_] : [INTEGER]) - [15]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([name3_12_] : [VARCHAR]) - [Examination2Name]
  ...
  </code></pre>
  
  <p>That is the expected behaviour. Is populating all Examinations data when getting all examinatios. But if I clean the cache, and execute again this method, I only get:</p>
  
  <pre><code>SQL [qtp684428083-26] - select examinatio0_.ID as ID1_12_, examinatio0_.duration as duration2_12_, examinatio0_.name as name3_12_ from examination_form examinatio0_
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([ID1_12_] : [BIGINT]) - [1]
  TRACE BasicExtractor [qtp684428083-26] - extracted value ([ID1_12_] : [BIGINT]) - [2]
  ...
  </code></pre>
  
  <p>Only IDs are retrieved. As in the GUI I can see the name and duration of each examination, means that the information is already available and hibernate does not need to retrieve it again. Therefore I am assuming that is cached somewhere.</p>
  
  <p>The questions are:</p>
  
  <ol>
  <li><p>How can I force to reload all these data from database again?</p></li>
  <li><p>Why getAll() is using cache if there is no annotation in the DAO's
  method neither in the entity to say that it must be cacheable. </p></li>
  <li><p>What is wrong in my <code>evictAllCache()</code> method?</p></li>
  </ol>
  
  <p>Obviously I am wrong somewhere but I am not able to find where. </p>