title: EhCache - not caching with spring data
body: <p>I have the following method:</p>
  
  <pre><code>@Scheduled(fixedRate = 20000)
  @Async
  public void test() {
  
  Operator operator = this.operatorRepository.findOne(1L);
  System.out.println(operator.getName());
  
  org.springframework.cache.ehcache.EhCacheCache c = (EhCacheCache) cacheManager.getCache("example");
  System.out.println("HIT: "+c.getNativeCache().getStatistics().getExtended().get().component(GetOutcome.HIT).count().value());
  System.out.println("MISS_EXPIRED: "+c.getNativeCache().getStatistics().getExtended().get().component(GetOutcome.MISS_EXPIRED).count().value());
  System.out.println("MISS_NOT_FOUND: "+c.getNativeCache().getStatistics().getExtended().get().component(GetOutcome.MISS_NOT_FOUND).count().value());
  
  System.out.println(c.getNativeCache().getStatistics().cacheHitOperation().count().value());
  System.out.println("MISS COUNT: " +c.getNativeCache().getStatistics().cacheMissCount());
  System.out.println("HIT COUNT: " +c.getNativeCache().getStatistics().cacheHitCount());
  System.out.println("MISS_EXPIRED COUNT: " +c.getNativeCache().getStatistics().cacheMissExpiredCount());
  System.out.println("CACHE_SIZE: " + c.getNativeCache().getStatistics().getSize());
  
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>HIT: 0
  MISS_EXPIRED: 0
  MISS_NOT_FOUND: 0
  0
  MISS COUNT: 0
  HIT COUNT: 0
  MISS_EXPIRED COUNT: 0
  CACHE_SIZE: 0
  </code></pre>
  
  <p>As you can see i'm using jpa repositories (spring-data) for my db operations. i configured a 2nd level cache. and yet no hits\misses.   my Operator entity is annotated like this:</p>
  
  <pre><code>@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 
  </code></pre>
  
  <p>here is my xml configurations:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
  
      &lt;property name="url" value="${mysql_url}" /&gt;
      &lt;property name="username" value="xxx" /&gt;
      &lt;property name="password" value="xxx" /&gt;
  
      &lt;property name="initialSize" value="10" /&gt;
      &lt;property name="maxActive" value="100" /&gt;
      &lt;property name="maxIdle" value="15" /&gt;
      &lt;property name="minIdle" value="10" /&gt;
      &lt;property name="timeBetweenEvictionRunsMillis" value="10000" /&gt;
      &lt;property name="minEvictableIdleTimeMillis" value="60000" /&gt;
  
      &lt;property name="validationQuery" value="/* ping */ SELECT 1" /&gt;
      &lt;property name="testOnBorrow" value="true" /&gt;
      &lt;property name="testWhileIdle" value="true" /&gt;
  
      &lt;property name="removeAbandoned" value="true" /&gt;
      &lt;property name="removeAbandonedTimeout" value="300" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
  
      &lt;property name="packagesToScan"
          value="com.xxx.model, com.xxx.shared.model" /&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
              &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.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt;
              &lt;prop key="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory&lt;/prop&gt;
              &lt;prop key="hibernate.generate_statistics"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property name="jpaDialect"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /&gt;
      &lt;/property&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="database" value="MYSQL" /&gt;
              &lt;property name="showSql" value="false" /&gt;
              &lt;property name="generateDdl" value="false" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="jpaPropertyMap"&gt;
          &lt;map&gt;
              &lt;entry key="hibernate.connection.autocommit" value="false" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  
  &lt;/bean&gt;
  </code></pre>
  
  <p>and my cache xml:</p>
  
  <pre><code>&lt;ehcache   name="test"&gt; 
  &lt;cache name="example" maxElementsInMemory="1000" eternal="false"  statistics="true" 
      overflowToDisk="false" timeToIdleSeconds="0" timeToLiveSeconds="600"&gt;
      &lt;cacheEventListenerFactory
          class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
          properties="replicateAsynchronously=false,replicatePuts=false
           ,replicateUpdates=true,replicateUpdatesViaCopy=false
           ,replicateRemovals=true"
          propertySeparator="," /&gt;
      &lt;bootstrapCacheLoaderFactory
          class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
          properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000" /&gt;
  &lt;/cache&gt;
  
  &lt;cacheManagerPeerProviderFactory
      class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
      properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
                  multicastGroupPort=4446, timeToLive=32" /&gt;
  &lt;cacheManagerPeerListenerFactory
      class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
      properties="hostName=localhost, port=40001, socketTimeoutMillis=2000" /&gt;
  &lt;/ehcache&gt; 
  </code></pre>
  
  <p>Any ideas why?</p>