2 Replies Latest reply on Mar 20, 2013 4:56 AM by james viet

    Spring 3.1 Hibernate 4 Infinispan jndi problem

    Yildirim Adiguzel Newbie

      Hi,

       

      I am trying to deploy my aplication to jboss-as 7.1.0.CR1b. But I am not able to configure session factory. My spring configuration like below

       

       

      <bean id="sessionFactory"

        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref="dataSource"/>

        <property name="hibernateProperties">

        <props>

                                              <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>

        <prop key="hibernate.hbm2ddl.auto">update</prop>

        <prop key="hibernate.cache.use_minimal_puts">true</prop>

        <prop key="hibernate.cache.use_structured_entries">true</prop>

        <prop key="hibernate.cache.use_second_level_cache">true</prop>

        <prop key="hibernate.cache.use_query_cache">true</prop>

        <prop key="hibernate.connection.release_mode">auto</prop>

        <prop key="hibernate.show_sql">true</prop>

        <prop key="hibernate.format_sql">false</prop>

                                              <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>

                                              <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>

        <prop key="hibernate.cache.infinispan.cachemanager">java:jboss/infinispan/hibernate</prop>

                                              <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory</prop>

        </props>

        </property>

        <property name="packagesToScan" value="com.granul.domain" />

      </bean>

       

      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

        <property name="jndiName" value="java:jboss/datasources/MyDatasourceDS" />

      </bean>


      <bean id="transactionManager"

        class="org.springframework.transaction.jta.JtaTransactionManager" />

       

       

      The exception is like below

       

       

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [adminApplicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.CacheException: Unable to retrieve CacheManager from JNDI [java:jboss/infinispan/hibernate]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) [spring-beans-3.1.0.RELEASE.jar:]

                ... 36 more

      Caused by: org.hibernate.cache.CacheException: Unable to retrieve CacheManager from JNDI [java:jboss/infinispan/hibernate]

                at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.locateCacheManager(JndiInfinispanRegionFactory.java:75) [hibernate-infinispan-4.0.1.Final.jar:]

                at org.hibernate.cache.infinispan.JndiInfinispanRegionFactory.createCacheManager(JndiInfinispanRegionFactory.java:64) [hibernate-infinispan-4.0.1.Final.jar:]

                at org.hibernate.cache.infinispan.InfinispanRegionFactory.start(InfinispanRegionFactory.java:275) [hibernate-infinispan-4.0.1.Final.jar:]

                at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:271) [hibernate-core-4.0.1.Final.jar:]

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:]

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775) [hibernate-core-4.0.1.Final.jar:]

                at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184) [spring-orm-3.1.0.RELEASE.jar:]

                at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314) [spring-orm-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) [spring-beans-3.1.0.RELEASE.jar:]

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) [spring-beans-3.1.0.RELEASE.jar:]

                ... 46 more

       

      Also my standalone xml attached


        • 1. Re: Spring 3.1 Hibernate 4 Infinispan jndi problem
          Galder Zamarreño Master

          We've recently updated the 2LC information for when you run on AS 7.1 and your config should be trimmed to remove some options.

           

          So, remove hibernate.cache.region.factory_class and it should work. When you run on AS7 and you enable 2LC, we automatically hook you into the Infinispan one. See https://docs.jboss.org/author/x/LoJ7 for more info.

          • 2. Re: Spring 3.1 Hibernate 4 Infinispan jndi problem
            james viet Newbie

            Hi Galder,

             

            When I removed "hibernate.cache.region.factory_class"

             

            I saw error:

            Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

                at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:69)

                at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:347)

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740)

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:189)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:350)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:335)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)

             

             

            Here is my configure, I use spring bean

             

                            hibernate.dialect=org.hibernate.dialect.MySQLDialect

                            hibernate.hbm2ddl.auto=update

                            jboss.as.jpa.providerModule=hibernate3-bundled

                            hibernate.cache.use_second_level_cache=true

                            hibernate.cache.use_query_cache=true

                            hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory

                            hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup

                            hibernate.jta.UserTransaction = UserTransaction

                            hibernate.transaction.flush_before_completion=true

                            hibernate.transaction.auto_close_session=true

                            hibernate.cache.infinispan.cfg=/tmp/infinispan-configs.xml

                            hibernate.generate_statistics=true

                            hibernate.jdbc.batch_size=30

                            shared-cache-mode=ENABLE_SELECTIVE

             

            Could you please give me some advise?