1

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.

Community
  • 1
  • 1
Sanjeev
  • 375
  • 1
  • 3
  • 14

2 Answers2

1

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.

uaiHebert
  • 1,882
  • 11
  • 21
  • I don't think that has to be done. As per Jboss Wildfly docu. no need to set it. Enabling JPA second level cache should be enough. But this not working for me. [link](https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide) – Sanjeev Mar 18 '15 at 08:42
  • If you look at the link that you post, you will find the same configuration that I posted above: – uaiHebert Mar 18 '15 at 16:13
0

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)

Padvinder
  • 971
  • 1
  • 6
  • 9