简体   繁体   English

无法使用ehcache配置JPA

[英]Not able to configure JPA with ehcache

I have been trying to configure JPA with ehcache but no success till now. 我一直在尝试使用ehcache配置JPA但直到现在都没有成功。 The configurations which i am doing are : 我正在做的配置是:

  • persistence.xml 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.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 Product.java

     @Entity @Table(name="PRODUCT") @NamedQueries({@NamedQuery(name="getAllProducts", query = "select products from Product products")}) public class Product implements Serializable {} 

I am not getting any exception but i could not see the ehcache working as nothing specific to ehcache printed in the logs. 我没有得到任何例外,但我看不到ehcache在日志中打印的ehcache没有特定的功能。 I would really appreciate if someone can help in this. 如果有人可以提供帮助,我将非常感激。

Add the following properties in persistence.xml: 在persistence.xml中添加以下属性:

<property name="openjpa.QueryCache" value="ehcache"/>
<property name="openjpa.DataCacheManager" value="ehcache"/>

Add the following jars in classpath: ehcache-core-2.4.4.jar , ehcache-openjpa-0.2.0.jar and slf4j-api-1.6.1.jar . 在类路径中添加以下jar: ehcache-core-2.4.4.jarehcache-openjpa-0.2.0.jarslf4j-api-1.6.1.jar

That's all. 就这样。

Jar Downloads: Jar下载:

References 参考

DataNucleus works perfectly fine with EHCache, with the config specified here http://www.datanucleus.org/products/accessplatform_2_2/jpa/cache.html#ehcache It will print log messages about the L2 cache whenever it is accessed. DataNucleus与EHCache完美配合,此处指定的配置http://www.datanucleus.org/products/accessplatform_2_2/jpa/cache.html#ehcache无论何时访问,它都会打印有关L2缓存的日志消息。 You don't mention your JPA provider. 您没有提到您的JPA提供商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM