2 Replies Latest reply on Jan 21, 2011 7:52 AM by swarnad

    Infinispan as Hibernate L2 Cache, cache provider exception

    swarnad

      Hi,

       

      I am trying to configure infinispan as hibernate l2 cache. We are using JPA hibernate spring and infinispan as cache.

       

      I am getting exception below when starting the tc server with application:

       

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [C:\springsource\tc-server-developer-2.1.0.RELEASE\spring-insight-instance\wtpwebapps\NearByADServer\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\springsource\tc-server-developer-2.1.0.RELEASE\spring-insight-instance\wtpwebapps\NearByADServer\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: MyPersistenceUnit] Unable to build EntityManagerFactory

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)

                at

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\springsource\tc-server-developer-2.1.0.RELEASE\spring-insight-instance\wtpwebapps\NearByADServer\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: MyPersistenceUnit] Unable to build EntityManagerFactory

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

      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyPersistenceUnit] Unable to build EntityManagerFactory

                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)

                at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)

            ... 46 more

      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.NoCacheProvider.buildCache(NoCacheProvider.java:21)

                at org.hibernate.cache.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:42)

                at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:337)

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

                at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

                ... 51 more

       

       

      My Persistence.xml looks like:

       

          <persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">

              <provider>org.hibernate.ejb.HibernatePersistence</provider>

              <properties>

                  <property name="hibernate.dialect" value="org.hibernatespatial.mysql.MySQLSpatialDialect"/>

                  <!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->

                  <!-- <property name="hibernate.hbm2ddl.auto" value="update"/> -->

                  <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>

                  <property name="hibernate.show_sql" value="true"/>

       

                  <property name="hibernate.session_factory_name" value="SessionFactories/infinispan"/>

       

       

                  <property name="hibernate.cache.use_query_cache" value="true" />

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

                  <property name="hibernate.generate_statistics" value="true" />

                  <property name="hibernate.cache.use_structured_entries" value="true"/>

       

       

                  <property name="hibernate.cache.region_prefix" value="infinispan" />

       

       

                  <property name="hibernate.show_sql" value="true" />

       

       

                  <!--property name=hibernate.cache.region.factory_class value=org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory />

                  <property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager" /-->

       

       

       

                  <!--property name=hibernate.cache.region.factory_class value=org.hibernate.cache.infinispan.JndiInfinispanRegionFactory/>

                  <property name="hibernate.cache.infinispan.cachemanager" value="java:CacheManager"/-->

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

       

       

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

                        <property name="hibernate.cache.use_query_cache" value="true"/>

       

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

                        <property name="hibernate.cache.infinispan.statistics" value="true"/>

                        <property name="hibernate.cache.infinispan.entity.eviction.strategy" value="LRU"/>

                        <property name="hibernate.cache.infinispan.entity.eviction.wake_up_interval" value="10000"/>

                        <property name="hibernate.cache.infinispan.entity.eviction.max_entries" value="5000"/>

                        <property name="hibernate.cache.infinispan.entity.expiration.lifespan" value="60000"/>

                        <property name="hibernate.cache.infinispan.entity.expiration.max_idle" value="30000"/>-->

              </properties>

          </persistence-unit>

       

      My applicationContext.xml looks like:

       

      <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">

              <property name="driverClassName" value="${database.driverClassName}"/>

              <property name="url" value="${database.url}"/>

              <property name="username" value="${database.username}"/>

              <property name="password" value="${database.password}"/>

          </bean>

          <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">

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

          </bean>

      <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>    

          <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">

                    <property name="persistenceUnitName" value="MyPersistenceUnit"/>

       

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

          </bean>

       

      As soon as I enable infinispan configuration, it starts giving the above exception. Is it because Cacheprovider is not mentioned? If so then what should be provided. I have infinispan jars and hibernate-infinispan jar in my classpath.

       

      Please provide some inputs.

        • 1. Re: Infinispan as Hibernate L2 Cache, cache provider exception
          galder.zamarreno

          Even though the XML appears to define the Infinispan region factory correctly:

           

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

           

          It seems like this is not being picked up. Maybe some the Infinispan 2LC jar missing? You might wanna see the rest of the log to see if there's any other error messages earlier. As a reference, the dependencies you need are:

           

          <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-infinispan</artifactId>
            <version>X</version>
          </dependency>

           

          Where X is Hibernate 3.5.x or 3.6.x. You need to make sure your war contains the Hibernate-Infinispan jar plus any dependant jars.

           

          Alternative, debug the code (with an IDE?) to figure out why NoCacheProvider is being selected.

          • 2. Re: Infinispan as Hibernate L2 Cache, cache provider exception
            swarnad

            Yes you pointed out correctly. The issue was due to incorrect version of hibernate jar. It got fixed after putting the required version of hibernate.

             

            Thanks for your help.