我添加了这些依赖项:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b11</version>
</dependency>
也
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.8.1</version>
</dependency>
我曾经也有过
properties.put ( Environment.CACHE_REGION_FACTORY, SingletonEhCacheRegionFactory.class.getName() );
和
property.put("net.sf.ehcache.configurationResourceName", "App/config/CacheConfig.xml")
where App/config/CacheConfig.xml
is:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="false">
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="false">
</defaultCache>
<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="false">
</cache>
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="300">
</cache>
<!--
If you are concerned about cpu utilisation and locking in the DiskStore, you can set the
diskExpiryThreadIntervalSeconds to a high number - say 1 day. Or you can effectively turn it off by
setting the diskExpiryThreadIntervalSeconds to a very large value
-->
<cache
name="br.com.atlantico.toi.model.calc.Anomalia"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"/>
</ehcache>
问题是当我尝试保留 SingletonEhCacheRegionFactory 时,它失败并出现错误:
Unable to resolve name [net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]
... java.lang.ClassNotFoundException
... org/hibernate/cache/TimestampsRegion
好吧,我上网查了一下,然后建议我使用:
properties.put(Environment.CACHE_REGION_FACTORY, JCacheRegionFactory.class.getName());
properties.put("hibernate.javax.cache.provider", EhcacheCachingProvider.class.getName());
and
properties.put("hibernate.javax.cache.uri", "App/config/CacheConfig.xml");
它有效(但旧的 ehcache 文件不起作用)。
然而,我相信现在使用的 JCache 必须通过注释实体来使用,而之前我只是在 CacheConfig.xml (ehcache) 中配置它。
问题1.
有没有办法继续在 Hibernate 5、Ehcache 3 中使用 SingletonEhCacheRegionFactory?
如果是这样怎么办。它并没有被弃用。
问题2。
这个新的 JCache 是什么?它只是方法返回缓存吗?我最感兴趣的是 Second_level_cache 和查询缓存。
问题3。如何将旧的 ehcache 转换为新的?我无法找到使用新版本的示例 ehcache 文件,因为使用旧版本基本上会导致解析错误。
org.xml.sax.SAXParseException
cvc-elt.1.a: Cannot find the declaration of element 'ehcache'.
请通过教育我来弥补我的知识不足。