简体   繁体   中英

JPA second level cache in wildfly8.2, hibernate-entitymanager 4.3.8.Final

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, eg) 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.

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM