用于L2缓存抛出的JPA 2.0 Ehcache配置错误

时间:2017-05-22 15:40:15

标签: jpa jpa-2.0 ehcache persistence.xml

我正在尝试为JPA 2.0配置Ehcache。 首先我已经设置了persistance.xml

<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>

我的课程路径中有ehcache.xml。 将@Cacheable(true)配置为我的@Entity课程。

我收到了以下错误。

 net.sf.ehcache.config.InvalidConfigurationException: There is one error in your configuration: 
    * Cache 'net.sf.ehcache.constructs.asynchronous.MessageCache' error: If your CacheManager has no maxBytesLocalHeap set, you need to either set maxEntriesLocalHeap or maxBytesLocalHeap at the Cache level

ehcache.xml中

<?xml version="1.0" encoding="UTF-8"?>



<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
    monitoring="autodetect" dynamicConfig="true">

    <!-- By default, Ehcache stored the cached files in temp folder. -->
    <!-- <diskStore path="java.io.tmpdir" /> -->

    <!-- Ask Ehcache to store cache in this path -->
    <diskStore path="c:\\cache" />

    <!-- Sample cache named cache1
    This cache contains a maximum in memory of 10000 elements, and will expire
    an element if it is idle for more than 5 minutes and lives for more than
    10 minutes.

    If there are more than 10000 elements it will overflow to the
    disk cache, which in this configuration will go to wherever java.io.tmp is
    defined on your system. On a standard Linux system this will be /tmp" -->


        <Cache name = "com.test.myDataDE"
        maxEntriesLocalHeap="10000"
        maxEntriesLocalDisk="1000"
        eternal="false"
        diskSpoolBufferSizeMB="20"
        timeToIdleSeconds="300" timeToLiveSeconds="600"
        memoryStoreEvictionPolicy="LFU"
        transactionalMode="off">
        <persistence strategy="localTempSwap" />
    </Cache>

</ehcache>

请帮助我理解我正在做的任何错误?

2 个答案:

答案 0 :(得分:0)

如果没有ehcache.xml内容,很难确定。

但是,鉴于错误消息,我认为问题是您没有为条目或字节中的缓存指定堆大小。

答案 1 :(得分:0)

我今天遇到了同样的问题,通过添加:

解决了这个问题
maxBytesLocalHeap="100M"

并删除:

maxEntriesLocalHeap

在我的ehcache.xml配置中。