title: JBoss EAP 7 and Ifinispan
body: <p>I have a web application which is written in JEE. I am using hibernate as a JPA provider and I would like to use Infinispan as a second level cache. As I went through internet I noticed that only adding several lines is needed. I added in my persistence.xml these lines</p>
  
  <pre><code>&lt;property name="hibernate.cache.provider_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/&gt;
  &lt;property name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE"/&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;
  </code></pre>
  
  <p>but during deploying ear and war file on JBoss I receive an error message</p>
  
  <pre><code>Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
          at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:242)
          at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
          ... 83 more
  Caused by: org.hibernate.cache.CacheException: Unable to start region factory
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:415)
          at org.hibernate.internal.CacheImpl.&lt;init&gt;(CacheImpl.java:49)
          at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:28)
          at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:20)
          at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:46)
          at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234)
          ... 88 more
  Caused by: org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="SampleCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element
          at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:52)
          at org.infinispan.jmx.CacheManagerJmxRegistration.updateDomain(CacheManagerJmxRegistration.java:79)
          at org.infinispan.jmx.CacheManagerJmxRegistration.buildRegistrar(CacheManagerJmxRegistration.java:73)
          at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:37)
          at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:41)
          at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:639)
          at org.infinispan.manager.DefaultCacheManager.&lt;init&gt;(DefaultCacheManager.java:300)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:532)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:500)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:473)
          at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:342)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:472)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:380)
          ... 93 more
  </code></pre>
  
  <p><strong>UPDATE</strong> <br/>
  When my persistence unit looks like this</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
               http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  
      &lt;persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;non-jta-data-source&gt;java:jboss/datasources/myDatasource&lt;/non-jta-data-source&gt;
      &lt;mapping-file&gt;META-INF/orm_mapping.xml&lt;/mapping-file&gt;
      &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
          &lt;shared-cache-mode&gt;ENABLE_SELECTIVE&lt;/shared-cache-mode&gt;
           ...
          &lt;properties&gt;
            ...
              &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
            ...
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;  
  </code></pre>
  
  <p>I am getting an exception</p>
  
  <pre><code>Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
          at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:66)
          at org.hibernate.internal.SessionFactoryImpl.determineEntityRegionAccessStrategy(SessionFactoryImpl.java:619)
          at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:332)
          at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
          at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
          ... 83 more
  </code></pre>
  
  <p>After adding below line to persistence.xml</p>
  
  <pre><code>&lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory" /&gt;
  </code></pre>
  
  <p>I am still getting exception with JMX MBean</p>
  
  <pre><code>Caused by: org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="SampleCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element
          at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:52)
          at org.infinispan.jmx.CacheManagerJmxRegistration.updateDomain(CacheManagerJmxRegistration.java:79)
          at org.infinispan.jmx.CacheManagerJmxRegistration.buildRegistrar(CacheManagerJmxRegistration.java:73)
          at org.infinispan.jmx.AbstractJmxRegistration.registerMBeans(AbstractJmxRegistration.java:37)
          at org.infinispan.jmx.CacheManagerJmxRegistration.start(CacheManagerJmxRegistration.java:41)
          at org.infinispan.manager.DefaultCacheManager.start(DefaultCacheManager.java:639)
          at org.infinispan.manager.DefaultCacheManager.&lt;init&gt;(DefaultCacheManager.java:300)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:532)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:500)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory$1.doWork(InfinispanRegionFactory.java:473)
          at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.workWithClassLoader(ClassLoaderServiceImpl.java:342)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.createCacheManager(InfinispanRegionFactory.java:472)
          at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:380)
          ... 93 more
  </code></pre>
  
  <p>Maybe I need some kind of infinispan config file where I will be able to place </p>
  
  <pre><code>&lt;jmx duplicate-domains="true" /&gt;
  </code></pre>
  
  <p>like it is mentioned here <a href="https://stackoverflow.com/questions/37311484/infinispan-as-second-level-cache-hibernate">Infinispan as second level cache hibernate
  </a> </p>