4 Replies Latest reply on Aug 13, 2013 5:57 PM by Shane Johnson

    java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"

    Vikram Murugesan Newbie

      I am trying to migrate my application from EAP 5.1.2 to EAP 6.0.1. We have been using JBoss Cache 2 previously and this is my first try at using Infinispan.

       

      I see this exception during app startup. As far as I understand in order to use Infinispan I have to add a module dependency in my jboss-deployment-structure.xml

       

      Here are the versions,

      • EAP Version - 6.0.1
      • standalone-full-ha

       

       

      {code}11:00:58,899 ERROR [com.myapp.core.hibernate.HibernateUtil] (MSC service thread 1-8) Initial SessionFactory creation failed.: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"]

                at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:410) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at com.myapp.core.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:75) [myapp-core-10.0.0-HEAD-SNAPSHOT.jar:]

                at com.myapp.MyappListener.contextInitialized(MyappListener.java:74) [classes:]

                at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final-redhat-1.jar:]

                at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final-redhat-1.jar:]

                at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final-redhat-4.jar:7.1.3.Final-redhat-4]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExAecutor.java:1145) [rt.jar:1.7.0_25]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]

                at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

      Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"]

                at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:393) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                ... 14 more

      Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"

                at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                at java.lang.ClassLoader.loadClass(ClassLoader.java:424) [rt.jar:1.7.0_25]

                at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [rt.jar:1.7.0_25]

                at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_25]

                at java.lang.Class.forName(Class.java:270) [rt.jar:1.7.0_25]

                at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                ... 15 more{code}

       

       

       

      Here is the subdeployment section of my jboss-deployment-structure.xml

       

      {code:xml}

      <sub-deployment name="mywebapp.war">

                <dependencies>

                          <module name="javax.api" />

                          <module name="javax.persistence.api" />

                          <module name="org.hibernate" />

                          <module name="org.infinispan" />

                </dependencies>

       

                <resources>

                          <resource-root path="mydependency.jar"/>

                </resources>

       

       

                <local-last value="false" />

      </sub-deployment>

      {code}

       

      Here is part of my hibernate.cfg.xml

       

      {code:xml}

      <property name="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"</property>

      <property name="hibernate.cache.infinispan.cachemanager">java:jboss/infinispan/hibernate"</property>

      <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

      <property name="hibernate.cache.use_second_level_cache">true</property>

      <property name="hibernate.cache.use_minimal_puts">true</property>

      {code}

       

      I know this is pretty straight forward, but not sure why it is not loading the infinispan jar. I see that org/hibernate/main directory has both infinispan jar and hibernate jar. Also module.xml of org.hibernate lists the infinispan jar as a resource. Appreciate any help. I would be glad to provde more details.

        • 1. Re: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"
          Shane Johnson Novice

          Are you using JPA?

           

          If so, you don't have to worry about configuring Hibernate to use Infinispan. The only required property is the "hibernate.cache.use_second_level_cache" property. Feel free to take a look at my reference project:

           

          https://github.com/shane-k-j/jboss-trading/blob/master/trading-beans/src/main/resources/META-INF/persistence.xml

          • 2. Re: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"
            Vikram Murugesan Newbie

            Shane,

             

            Thanks for your response.

             

            We are not using JPA, we use hibernate directly.

            • 3. Re: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"
              Vikram Murugesan Newbie

              Also, I already tried without providing the region factory class, This is what I got,

               

              {code}

              16:49:47,651 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/myapp]] Exception sending context initialized event to listener instance of class com.myaapp.MyappListener: java.lang.ExceptionInInitializerError

                        at com.myapp.core.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:82) [cips-core-10.0.0-HEAD-SNAPSHOT.jar:]

                        at com.myapp.MyappListener.contextInitialized(MyappListener.java:74) [classes:]

                        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.17.Final-redhat-1.jar:]

                        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.17.Final-redhat-1.jar:]

                        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:89) [jboss-as-web-7.1.3.Final-redhat-4.jar:7.1.3.Final-redhat-4]

                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]

                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]

                        at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]

              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:186) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:262) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1746) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at com.myapp.core.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:75) [cips-core-10.0.0-HEAD-SNAPSHOT.jar:]

                        ... 9 more

              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 class name to property hibernate.cache.region.factory_class (and make sure the second level cache provider, hibernate-infinispan, for example, is available in the classpath).

                        at org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:87) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:63) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:72) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176) [hibernate-core-4.1.6.Final-redhat-3.jar:4.1.6.Final-redhat-3]

                        ... 14 more

              {code}