升级到Hibernate5并配置ehcache不起作用jcache现在?

z5btuh9x  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(157)

我添加了这些依赖项:

<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()  );

和properties.put(“net.sf.ehcache.configurationresourcename”,“app/config/cacheconfig.xml”)
哪里 App/config/CacheConfig.xml 是:

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

问题是,当我尝试保持singletoneCacheRegionFactory时,它失败并出现错误:

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());

properties.put("hibernate.javax.cache.uri", "App/config/CacheConfig.xml");

它可以工作(但是旧的ehcache文件不工作)。
但是,我认为jcache use now必须通过注解实体来使用,而在我刚刚在cacheconfig.xml(ehcache)中配置它之前。
问题1。
有没有办法继续在hibernate 5、ehcache 3中使用singletonehcacheregionfactory?如果是,怎么办。它没有被否决。
问题2。
这个新的jcache是什么,它是唯一的方法返回缓存吗?我最感兴趣的是二级缓存和查询缓存。
问题3。如何将旧的ehcache转换为新的ehcache?我还没有找到使用新版本的示例ehcache文件,因为输入旧版本基本上会导致解析错误。

org.xml.sax.SAXParseException
          cvc-elt.1.a: Cannot find the declaration of element 'ehcache'.

请通过教育我来弥补我知识的不足。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题