3.2.2.10. Replace JPA/Hibernate Second Level Cache with Infinispan
Summary
JBoss Cache has been replaced by Infinispan for second-level cache (2LC). This requires a change to the persistence.xml file. The syntax is slightly different, depending on if you are using JPA or Hibernate second level cache. These examples assume you are using Hibernate.
This is an example of how properties for second level cache were specified in the
persistence.xml file in JBoss EAP 5.x.
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
<property name="hibernate.cache.region_prefix" value="services"/>
The following steps will use this example to configure Infinispan in JBoss EAP 6.
Procedure 3.16. Modify the persistence.xml file to use Infinispan
Configure Infinispan for a JPA application in JBoss EAP 6
This is how you specify properties to achieve the same configuration for a JPA application using Infinispan in JBoss EAP 6:<property name="hibernate.cache.use_second_level_cache" value="true"/>
In addition, you need to specify ashared-cache-modewith a value ofENABLE_SELECTIVEorALLas follows:ENABLE_SELECTIVEis the default and recommended value. It means entities are not cached unless you explicitly mark them as cacheable.<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
ALLmeans entities are always cached even if you mark them as not cacheable.<shared-cache-mode>ALL</shared-cache-mode>
Configure Infinispan for a native Hibernate application in JBoss EAP 6
This is how you specify the same configuration for a native Hibernate application using Infinispan with JBoss EAP 6:<property name="hibernate.cache.region.factory_class" value="org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory"/> <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> <property name="hibernate.cache.use_second_level_cache" value="true"/>You must also add the following dependencies to theMANIFEST.MFfile:Manifest-Version: 1.0 Dependencies: org.infinispan, org.hibernate
For more information about Hibernate cache properties, see: Section 3.2.2.11, “Hibernate Cache Properties”.