1 Reply Latest reply on Apr 25, 2013 1:38 AM by Nicklas Karlsson

    Unable to set up Infinispan as Hibernate L2 cache provider

    Peter Temk Newbie

      I'm trying to test use of Infinispan as Hibernate second level cache provider but I'm not able to come up with a working configuration and since I'm quite new to the system, I would appreciate very much if somebody could give me a hint what I'm doing wrong.

       

      My setup is following:

       

      I put together very simple web application based on Hibernate tutorial (http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html/ch01.html#tutorial-firstapp).

      I use Maven to build the application and produce a war file. I want to use modules provided by my JBoss installation (version AS 7.1.3 from EAP 6.0.1) - I set dependencies in the project pom as "provided" and put them in jboss-deployment-structure.xml file.

      I run the server in domain mode and deploy the application war manually via the management console.

       

      The first problem comes up when I try to load it, I get java.lang.ClassNotFoundException:

      java.lang.ClassNotFoundException: Could not load requested class : oracle.jdbc.driver.OracleDriver

      org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)

      java.lang.ClassLoader.loadClass(ClassLoader.java:423)

      java.lang.ClassLoader.loadClass(ClassLoader.java:356)

      java.lang.Class.forName0(Native Method)

      java.lang.Class.forName(Class.java:266)

      org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)

      org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:104)

      org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)

      org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)

      org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)

      org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)

      org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)

      org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)

      org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)

      org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)

      org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)

      org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279)

      org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275)

      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)

      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)

      org.hibernate.tutorial.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)

      org.hibernate.tutorial.util.HibernateUtil.<clinit>(HibernateUtil.java:8)

      org.hibernate.tutorial.web.EventManagerServlet.doGet(EventManagerServlet.java:23)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

       

      even though I have ojdbc dependency set:

       

      pom.xml:

      ...

      <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-core</artifactId>

                  <version>4.1.6.Final-redhat-3</version>

                  <scope>provided</scope>

      </dependency>

      <dependency>

                  <groupId>com.oracle</groupId>

                  <artifactId>ojdbc6</artifactId>

                  <version>11.2.0.3</version>

                  <scope>provided</scope>

      </dependency>

      ...

       

      jboss-deployment-structure.xml:

      ...

      <dependencies>

      ...

                <module name="org.hibernate" />

                <module name="com.oracle.ojdbc6" />

      ...

      </dependencies>

      ...

       

      After some experimenting I found out I can get rid of the error if I don't set hibernate-core dependency as "provided" and I bundle the module with war (although I haven't figured out why and how to make it work with provided JBoss module). Application works as expected then so I've tried to turn on the second level cache.

       

      I edited my hibernate.cfg.xml file as described here: https://docs.jboss.org/author/display/AS72/JPA+Reference+Guide#JPAReferenceGuide-UsingtheInfinispansecondlevelcache and, since got a class not found error, added jboss-as-jpa-hibernate4 to my dependencies. When I try to load the application now, I get ClassCastException:

      java.lang.ClassCastException: org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory cannot be cast to org.hibernate.cache.spi.RegionFactory

      org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:393)

      org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264)

      org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279)

      org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275)

      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)

      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)

      org.hibernate.tutorial.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)

      org.hibernate.tutorial.util.HibernateUtil.<clinit>(HibernateUtil.java:8)

      org.hibernate.tutorial.web.EventManagerServlet.doGet(EventManagerServlet.java:23)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

       

      I've tried to apply advice previously given in similar situations, like setting JNDI name or eager start for Infinispan container in domain.xml configuration (in alternative configuration with <property name="hibernate.cache.infinispan.cachemanager">java:jboss/infinispan/hibernate</property>), but nothing helped so far. Any ideas anybody, please?