I have been trying to configure JPA with ehcache but no success till now. The configurations which i am doing are :
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 {}
I am not getting any exception but i could not see the ehcache working as nothing specific to ehcache printed in the logs. I would really appreciate if someone can help in this.
Add the following properties in 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
.
That's all.
Jar Downloads:
ehcache-core-2.4.4.jar
and slf4j-api-1.6.1.jar
- ehcache-core-2.4.4-distribution.tar.gz moduleehcache-openjpa-0.2.0.jar
- ehcache-openjpa-0.2.0-distribution.tar.gz
References
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With