您好我遇到了休眠二级缓存的一些问题。 作为缓存提供者,我使用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) public class Kierunek implements 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=""/>
,并且删除了错误的前缀大THX鲁斯兰!
你应该完全拼出单词“level”而不是“lvl”。它更具可读性和可读性。 – 2009-04-19 19:29:33
你说得对。我正在写这篇文章,感觉很沮丧,所以我没有想过这件事^^谢谢 – Dogrizz 2009-04-19 20:38:59