开发者

Not able to configure JPA with ehcache

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 getti开发者_如何学Gong 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:

  • link - http://ehcache.org/downloads/catalog?activated=true
  • ehcache-core-2.4.4.jar and slf4j-api-1.6.1.jar - ehcache-core-2.4.4-distribution.tar.gz module
  • ehcache-openjpa-0.2.0.jar - ehcache-openjpa-0.2.0-distribution.tar.gz

References

  • L2 caching explained - http://blogs.oracle.com/carolmcdonald/entry/jpa_caching
  • OpenJPA L2 caching implementation - http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_caching.html
  • Ehcache OpenJPA implementation - http://www.ehcache.org/documentation/user-guide/openjpa-provider


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. You don't mention your JPA provider.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜