【发布时间】:2010-10-20 09:28:07
【问题描述】:
您好,我在使用休眠二级缓存时遇到了一些问题。 作为缓存提供者,我使用 ehcache。
persistence.xml 中的部分配置
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml" />
我使用注释配置我的实体:
@Cache(region = "Kierunek", usage = CacheConcurrencyStrategy.READ_WRITE)
公共类 Kierunek 实现 Serializable {
这些注释的导入是:
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
我的 ehcache.xml
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
diskSpoolBufferSizeMB="30" maxElementsOnDisk="10000000"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" />
<cache name="Kierunek" maxElementsInMemory="1000"
eternal="true" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
有人知道我为什么会出现以下错误吗?
WARNING: Could not find a specific ehcache configuration for cache named [persistence.unit:unitName=pz2EAR.ear/pz2EJB.jar#pz2EJB.Kierunek]; using defaults.
19:52:57,313 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=pz2EAR.ear/pz2EJB.jar#pz2EJB state=Create
java.lang.IllegalArgumentException: Cache name cannot contain '/' characters.
解决方案是在persistence.xml中添加另一个属性
<property name="hibernate.cache.region_prefix" value=""/>
并且删除了那个错误的前缀 big thx ruslan!
【问题讨论】:
-
你应该完整地拼出单词“level”而不是“lvl”。它更具可读性和可搜索性。
-
你是对的。我写这篇文章很沮丧,所以我没有考虑过^^谢谢
标签: java hibernate annotations ehcache