1
votes

I am trying to use second level cache in wildfly8.2 I am setting the properties via JavaConfig Properties properties = new Properties(); properties.setProperty("hibernate.hbm2ddl.auto", hibernateHbm2ddlAuto); properties.setProperty("hibernate.dialect", hibernateDialect); properties.setProperty("hibernate.show_sql", "true"); properties.setProperty("hibernate.cache.use_second_level_cache", "true"); properties.setProperty("hibernate.cache.use_query_cache" , "true");

but I get the following error

  • Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.

Why is it giving that error as per documentation it is not required. Any input would be helpful.

JPA shared cache / second level cache in WildFly

Thanks Sanjeev.

2

2 Answers

1
votes

You need to define the property hibernate.cache.region.factory_class, something like:

Configuration.setProperty("hibernate.cache.region.factory_class", "net.sf.ehcache.hibernate.EhCacheRegionFactory")

I would use C3P0 or Infinispam as second level cache.

0
votes

In my case I had unneeded persistence.xml file in subproject that was making wildfly wild - it was overriding configuration file.

Property <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/> was completely ignored. After removing(renaming) persistence.xml, wildfly would start again correctly with properties from database.xml. Hope it saves you some time (Wildfly 9.0.1Final, Hibernate 4.3.6.Final)