2017-05-05 158 views
1

即時得到這個錯誤:Hibernate配置 - NoCacheRegionFactoryAvailableException

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. 

但我有一個屬性集:

<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> 

即時通訊中使用Hibernate 4.3.10.Final和我所有的依賴。

回答

0

NoCacheRegionFactoryAvailableException上設置異常斷點,並檢查缺少的內容。這個錯誤響了,但我不記得確切的原因。但這就是我對它的調試方式。

您使用Ehcache 3嗎?因爲目前的提供者是用於Ehcache 2的。

0

我得到了與SpringBoot和Hibernate相同的錯誤。版本存在一些問題。這link幫助了我。

我用Spring Boot 1.5.1Hibernate 5.2.8和修改hibernate.properties文件如下:

hibernate.cache.use_second_level_cache=true 
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 

添加對實體緩存註釋:

@Entity 
@Table(name="test") 
@Cacheable 
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) 
public class Test{ 
} 
+0

雖然此鏈接可以回答這個問題,最好是包括答案的基本部分,並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/17983345) – EJoshuaS

+0

謝謝@EJoshuaS,我修改了答案。 –