org.hibernate.cache.CacheException:HIBERNATE不支持动态创建JCache Cache对象

问题描述 投票:0回答:1

我正在使用hibernate 5.3.3,hibernate-ehcache 5.3.1和ehcahe 3.2。用Java 8。

我在hibernate.cfg.xml中添加了以下配置

<property name="cache.use_second_level_cache">true</property>
<property name="cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory
</property>
<property name="hibernate.cache.use_query_cache">true</property>

我在我的实体类中添加了以下注释。

@Cacheable
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)

我在互联网上搜索但我没有找到以下异常的任何答案。

`Caused by: org.hibernate.cache.CacheException: On-the-fly creation of JCache Cache objects is not supported [default-update-timestamps-region]
    at org.hibernate.cache.ehcache.internal.EhcacheRegionFactory.createCache(EhcacheRegionFactory.java:106)
    at org.hibernate.cache.ehcache.internal.EhcacheRegionFactory.getOrCreateCache(EhcacheRegionFactory.java:100)
    at org.hibernate.cache.ehcache.internal.EhcacheRegionFactory.createTimestampsRegionStorageAccess(EhcacheRegionFactory.java:86)
    at org.hibernate.cache.spi.support.RegionFactoryTemplate.buildTimestampsRegion(RegionFactoryTemplate.java:70)
    at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:80)
    at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:33)
    at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:24)
    at org.hibernate.service.spi.SessionFactoryServiceInitiator.initiateService(SessionFactoryServiceInitiator.java:30)
    at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:68)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
    ... 21 more`
java hibernate caching ehcache second-level-cache
1个回答
0
投票

EhCacheRegionFactory用于连接Ehcache 2.x.你说你使用的是Ehcache 3.2,这很好。但它也意味着你应该使用org.hibernate.cache.jcache.JCacheRegionFactory来配置它。

© www.soinside.com 2019 - 2024. All rights reserved.