Reputation: 1118
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.
I'm using Hibernate as the JPA provider and these are my configs.
standalon-ha.xml in wildfly.
<cache-container name="hibernate">
<transport lock-timeout="60000"/>
<local-cache name="local-query">
<object-memory size="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<invalidation-cache name="entity">
<transaction mode="NON_XA"/>
<object-memory size="10000"/>
<expiration max-idle="100000"/>
</invalidation-cache>
<replicated-cache name="timestamps"/>
</cache-container>
persistance.xml
<persistence-unit name="mysqlPersistenceUnit" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--<exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<shared-cache-mode>ALL</shared-cache-mode>
<jta-data-source>java:/DataSourceName</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.archive.autodetection" value="class"/>
<!--<property name="hibernate.show_sql" value="true"/>-->
<!--<property name="hibernate.format_sql" value="true"/>-->
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<!-- cache -->
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.cache.infinispan.statistics" value="true"/>
</properties>
Entities
@Entity
@Cacheable
@Table(name = "table_name")
public class EntityName implements Serializable { // }
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.
[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)
Upvotes: 2
Views: 1519
Reputation: 11
In my case hibernate demanded hint for query:
final EntityManager em = getEntityManager();
...
return em.createQuery(all).setHint("org.hibernate.cacheable", Boolean.TRUE).getResultList();
Upvotes: 0