'Hibernate configuration - NoCacheRegionFactoryAvailableException
Im getting this 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.
But i have that property set:
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>
Im Using Hibernate 4.3.10.Final and i have all the dependencies.
Solution 1:[1]
I got the same error with SpringBoot and Hibernate. There was some issue with the versions. This link helped me.
I used Spring Boot 1.5.1 and Hibernate 5.2.8 and modified hibernate.properties file as below:
hibernate.cache.use_second_level_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
Add caching annotations on the entity:
@Entity
@Table(name="test")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Test{
}
Solution 2:[2]
Put an exception breakpoint on NoCacheRegionFactoryAvailableException and check what is missing. This error rings a bell but I don't remember the exact cause. But that's how I debugged it.
Are you using Ehcache 3? Because the current provider is for Ehcache 2.
Solution 3:[3]
I had the same error, I changed the version of hibernate in pom.xml
If you have the same error for old applications you can change the version and solved it.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.8.Final</version>
</dependency>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Henri |
| Solution 3 | David |
