org.hibernate.cache.CacheException: HIBERNATE 不支持即时创建 JCache 缓存对象

org.hibernate.cache.CacheException: On-the-fly creation of JCache Cache objects is not supported in HIBERNATE

我正在使用 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>

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

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

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