升级到Hibernate 5并配置EhCache不起作用现在的JCache?

问题描述

添加了以下依赖项:

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

问题是,当我尝试保留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());

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

有效(但是旧的ehcache文件无效)。

但是,我认为注释实体必须使用现在使用的jcache,而在我刚刚在CacheConfig.xml(ehcache)中对其进行配置之前。

问题1。

是否有办法继续将SingletonEhCacheRegionFactory与Hibernate 5,Ehcache 3结合使用? 如果是这样的话。它不被弃用。

问题2。

这个新的jcache是​​什么,是否只有方法返回缓存?我对Second_level_cache和查询缓存最感兴趣。

问题3。 如何将旧的ehcache转换为新的?我无法使用新版本找到示例ehcache文件,因为提供旧版本基本上会导致解析错误

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...