title: How to configure WIldfly infinispan subsystem for JPA L2 Cache?
body: <p>I'm trying to enable JPA L2 cache on Wildfly 14. Even though I have added the configuration caching is not taking place. Logs say entities are being cached but it seems the cache is not used when retrieving them.  </p>
  
  <p>I'm using Hibernate as the JPA provider and these are my configs.  </p>
  
  <ul>
  <li><p>standalon-ha.xml in wildfly.  </p>
  
  <pre><code>&lt;cache-container name="hibernate"&gt;
      &lt;transport lock-timeout="60000"/&gt;
      &lt;local-cache name="local-query"&gt;
          &lt;object-memory size="10000"/&gt;
          &lt;expiration max-idle="100000"/&gt;
      &lt;/local-cache&gt;
      &lt;invalidation-cache name="entity"&gt;
          &lt;transaction mode="NON_XA"/&gt;
          &lt;object-memory size="10000"/&gt;
          &lt;expiration max-idle="100000"/&gt;
      &lt;/invalidation-cache&gt;
      &lt;replicated-cache name="timestamps"/&gt;
  &lt;/cache-container&gt;
  </code></pre></li>
  <li><p>persistance.xml  </p>
  
  <pre><code>&lt;persistence-unit name="mysqlPersistenceUnit" transaction-type="JTA"&gt;
  &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  &lt;!--&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;--&gt;
  &lt;shared-cache-mode&gt;ALL&lt;/shared-cache-mode&gt;
  &lt;jta-data-source&gt;java:/DataSourceName&lt;/jta-data-source&gt;
  &lt;properties&gt;
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
      &lt;property name="hibernate.archive.autodetection" value="class"/&gt;
      &lt;!--&lt;property name="hibernate.show_sql" value="true"/&gt;--&gt;
      &lt;!--&lt;property name="hibernate.format_sql" value="true"/&gt;--&gt;
      &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/&gt;
      &lt;!-- cache --&gt;
      &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
      &lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/&gt;
      &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt;
      &lt;property name="hibernate.generate_statistics" value="true" /&gt;
      &lt;property name="hibernate.cache.infinispan.statistics" value="true"/&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p></p></li>
  </ul>
  
  <p></p>
  
  <ul>
  <li><p>Entities</p>
  
  <pre><code>@Entity
  @Cacheable
  @Table(name = "table_name")
  public class EntityName implements Serializable { // }
  </code></pre></li>
  </ul>
  
  <p>This is the output I am getting from Hibernate when database queries are executed. And each time I can see the db queries are being made.</p>
  
  <pre><code>[org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics {
  664166 nanoseconds spent acquiring 2 JDBC connections;
  125120 nanoseconds spent releasing 2 JDBC connections;
  1002407 nanoseconds spent preparing 2 JDBC statements;
  989037118 nanoseconds spent executing 2 JDBC statements;
  0 nanoseconds spent executing 0 JDBC batches;
  1994332 nanoseconds spent performing 2 L2C puts;
  0 nanoseconds spent performing 0 L2C hits;
  0 nanoseconds spent performing 0 L2C misses;
  366780 nanoseconds spent executing 1 flushes (flushing a total of 2 entities and 0 collections);
  201076 nanoseconds spent executing 2 partial-flushes (flushing a total of 1 entities and 1 collections)
  </code></pre>