[英]Not able to configure EhCache for hibernate 4.1.1 as it throws “ net/sf/ehcache/CacheException”
[英]Not able to configure JPA with ehcache
我一直在嘗試使用ehcache配置JPA但直到現在都沒有成功。 我正在做的配置是:
persistence.xml中
<persistence-unit name="customDatabase"> <jta-data-source>jdbc/oracleXE_DS</jta-data-source> <class>com.td.waw.cse.entities.Product</class> <properties> <property name="openjpa.Log" value="DefaultLevel=TRACE, Runtime=INFO, Tool=INFO, SQL=TRACE"/> <property name="openjpa.QueryCache" value="net.sf.ehcache.openjpa.datacache.EhCacheQueryCache"/> <property name="openjpa.DataCacheManager" value="net.sf.ehcache.openjpa.datacache.EhCacheDataCacheManager"/> <property name="openjpa.DataCache" value="net.sf.ehcache.openjpa.datacache.EhCacheDataCache"/> <property name="openjpa.RemoteCommitProvider" value="net.sf.ehcache.openjpa.datacache.NoOpRemoteCommitProvider"/> </properties>
ehcache.xml中
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true" > <defaultCache maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" /> <!-- OpenJPA data cache --> <cache name="openjpa" maxElementsInMemory="5000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" /> <!-- OpenJPA query cache --> <cache name="openjpa-querycache" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" /> </ehcache>
Product.java
@Entity @Table(name="PRODUCT") @NamedQueries({@NamedQuery(name="getAllProducts", query = "select products from Product products")}) public class Product implements Serializable {}
我沒有得到任何例外,但我看不到ehcache在日志中打印的ehcache沒有特定的功能。 如果有人可以提供幫助,我將非常感激。
在persistence.xml中添加以下屬性:
<property name="openjpa.QueryCache" value="ehcache"/>
<property name="openjpa.DataCacheManager" value="ehcache"/>
在類路徑中添加以下jar: ehcache-core-2.4.4.jar
, ehcache-openjpa-0.2.0.jar
和slf4j-api-1.6.1.jar
。
就這樣。
Jar下載:
ehcache-core-2.4.4.jar
和slf4j-api-1.6.1.jar
-core-2.4.4-distribution.tar.gz module ehcache-openjpa-0.2.0.jar
- ehcache-openjpa-0.2.0-distribution.tar.gz 參考
DataNucleus與EHCache完美配合,此處指定的配置http://www.datanucleus.org/products/accessplatform_2_2/jpa/cache.html#ehcache無論何時訪問,它都會打印有關L2緩存的日志消息。 您沒有提到您的JPA提供商。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.