Infinispan as Hibernate L2 Cache, cache provider exception
swarnad Jan 15, 2011 12:54 PMHi,
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.