5 Replies Latest reply on Mar 20, 2013 4:01 AM by jamesviet

    CacheException: Unable to start region factory

    siddharth.shah

      Hello,

       

      Configuring Hibernate (3.5.4) with Infinispan (4.1.0) as a second level cache on Jboss AS (6 - M4)

      Followed the guide at http://community.jboss.org/wiki/UsingInfinispanasJPAHibernateSecondLevelCacheProvider

       

      Now while configuring datasource created CacheManager in JBoss Local Tx Datasource

      Database connection successful while testing on AS admin console

       

      While getting error while creating hibernate's session factory

       

      19:37:30,150 INFO  [org.hibernate.impl.SessionFactoryImpl] building session factory
      19:37:30,150 INFO  [org.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
      19:37:30,150 ERROR [STDERR] org.hibernate.cache.CacheException: Unable to start region factory

      19:37:30,150 ERROR [STDERR]     at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:260)

      19:37:30,150 ERROR [STDERR]     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:250)

      19:37:30,150 ERROR [STDERR]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)

      19:37:30,150 ERROR [STDERR]     at manager.First.doGet(First.java:39)

      19:37:30,150 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

      19:37:30,150 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

      19:37:30,150 ERROR [STDERR]     at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:63)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

      19:37:30,150 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)

      19:37:30,150 ERROR [STDERR]     at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)

      19:37:30,150 ERROR [STDERR]     at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)

      19:37:30,150 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)

      19:37:30,150 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:93)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

      19:37:30,150 ERROR [STDERR]     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

      19:37:30,150 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

      19:37:30,150 ERROR [STDERR]     at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)

      9:37:30,150 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

      19:37:30,150 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

      19:37:30,166 ERROR [STDERR]     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)

      19:37:30,166 ERROR [STDERR]     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)

      19:37:30,166 ERROR [STDERR]     at java.lang.Thread.run(Unknown Source)

      19:37:30,166 ERROR [STDERR] Caused by: java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to org.infinispan.manager.CacheManager

      19:37:30,166 ERROR [STDERR]     at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.locateCacheManager(JndiInfinispanRegionFactory.java:75)

      19:37:30,166 ERROR [STDERR]     at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.createCacheManager(JndiInfinispanRegionFactory.java:68)

      19:37:30,166 ERROR [STDERR]     at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:246)

      19:37:30,166 ERROR [STDERR]     ... 27 more

      19:37:47,635 INFO  [org.rhq.core.pc.inventory.RuntimeDiscoveryExecutor] Running runtime discovery scan rooted at [platform]
      19:37:48,025 INFO  [org.rhq.core.pc.inventory.RuntimeDiscoveryExecutor] Scanned [0] servers and found [0] total descendant Resources.

       

      Database : Postgresql (8.4.3)

       

      Properties Related to Infinspan configuration

       

                     <property name="hibernate.cache.use_second_level_cache">true</property>
                      <property name="hibernate.cache.use_query_cache">true</property>
                      <property name="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory</property>
                      <property name="hibernate.cache.infinispan.cachemanager">java:CacheManager</property>
                      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
                      <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                      <property name="hibernate.cache.infinispan.statistics">true</property>

       

      So, What's worng over here ??

       

      2 ) I have defined properties related to DB connectivity in hibernate configuration file while cache is using datasource from AS. Can configuring single connectivity serve to both ?

       

      Thanks,

      Siddharth

        • 1. Re: CacheException: Unable to start region factory
          siddharth.shah

          It will be great help, If any can address the issue

           

          I think some thing is misconfigured or missed out while configuring Insinspan as a 2LC for hibernate

           

          Configure DataSource CacheManager in JBoss Local Tx Datasource from Jboss admin console and using same from

          <property  name="hibernate.cache.infinispan.cachemanager">java:CacheManager</property> from hibernate.cfg.xml

           

          no, while I am getting hibernate sessionfactory (database connection) getting exception

          java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to org.infinispan.manager.CacheManager

           

          Let me know if I am overlooked

           

          Thanks,

          Siddharth

          • 2. Re: CacheException: Unable to start region factory
            galder.zamarreno

            Most likely the issue is that you don't have an Infinispan CacheManager in JNDI.

             

            See the important note in the wiki: " Important note: JBoss Application Server might at some point have a common Infinispan cache manager that can be shared by all services but as of AS 6.0.0 M3 this yet not true. If you still want to deploy Infinispan 2LC this way, make sure you bind the CacheManager to JNDI. For more info on this, check the technical FAQ wiki."

             

            If you wanna avoid all this JNDI stuff, simply use the following and remove hibernate.cache.infinispan.cachemanager property:

             

            <!-- If using to Hibernate, add to your hibernate.cfg.xml -->
            <property name="hibernate.cache.region.factory_class">
               org.hibernate.cache.infinispan.InfinispanRegionFactory
            </property>
            • 3. Re: CacheException: Unable to start region factory
              siddharth.shah

              Thanks for reply Galder,

               

              1) I want to deploy application in JBoss cluster and need to use Infinispan cache as a cluster transactionl cache

              So does JNDI based lookup necessary ( XA-Resource for 2 phase commit ) for getting connection or JDBC stuff will do ?

               

              2) While I am avoiding JNDI based stuff, application can able to read data but wirte and not throwing any exception with defined Infispan configuration, What can be reason over here ?

               

                           <property name="hibernate.cache.infinispan.cachemanager">java:testXA</property>
                           <property name="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</property>    
                           <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                           <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

               

               

              3) I have deployed application with AS 6 M2, Still I am not able to cast datasource to Infinispan cachemanager

               

              Please let me know any more information required ?

               

              Thanks,

              Siddharth

              • 4. Re: CacheException: Unable to start region factory
                galder.zamarreno

                Re 1) JNDI has nothing to do wrt how Infinispan works. It's just where the CacheManager reference is retrieved from.

                 

                Re 2) No, why do you keep configuring hibernate.cache.infinispan.cachemanager? Forget about this property. It's only relevant for JNDI access to Infinispan cache manager.

                 

                Re 3) Why are you trying to cast a datasource to Infinispan CacheManager? You're mixing things up. It's your hibernate or JPA app that needs to be configured with a datasource. Infinispan does not need to know anything about the datasource used Hibernate or JPA. To configure Hibernate/JPA with the corresponding datasource, check their docu.

                • 5. Re: CacheException: Unable to start region factory
                  jamesviet

                  Hi Galder,

                   

                  Do we need

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

                  in config of Hibernate to use L2C? I thinh it is not necessary, right?