What is the correct settings to enable JPA Level 2 Caching?

721 views Asked by At

I am trying to figure out how to configure JPA 2.0 to use Memcache as the Level 2 cache in Google App Engine 1.8.7.

I have found instructions that are a year old and they don't work now.

Here is the error(s) that I am getting:

When I use <property name="datanucleus.cache.level2.type" value="jcache" /> I get the following error:

With core 3.1.4 / cache 3.1.2:

[INFO] Caused by: net.sf.jsr107cache.CacheException: Could not find class: 'ri.cache.BasicCacheFactory'

With core 3.1.2 / cache 3.1.2:

[INFO] Caused by: org.datanucleus.exceptions.NucleusUserException: Level 2 Cache "jcache" is registered to use class "org.datanucleus.cache.jcache.JCacheLevel2Cache" yet this is not found. Please check your CLASSPATH and plugin specification.

I haven't been able to figure out what to add where to resolve either issue.

When I use <property name="datanucleus.cache.level2.type" value="javax.cache" /> I get the following error:

[INFO] Caused by: org.datanucleus.exceptions.NucleusUserException: Level 2 Cache "javax.cache" is registered to use class "org.datanucleus.cache.JavaxCacheLevel2Cache" yet this is not found. Please check your CLASSPATH and plugin specification.

I have tried the following settings in my persistence.xml and neither works:

Here are my relevant configuration settings:

persistence.xml

<property name="datanucleus.cache.level2.name" value="entitycache" />
<property name="datanucleus.cache.level2.type" value="javax.cache" />

and

<property name="datanucleus.cache.level2.name" value="entitycache" />
<property name="datanucleus.cache.level2.type" value="jcache" />

pom.xml

<properties>
    <resteasy.version>3.0.5.Final</resteasy.version>
    <jackson.version>2.2.3</jackson.version>
    <gae.version>1.8.7</gae.version>
    <gae-runtime.version>1.8.0</gae-runtime.version>
    <gae.home>/Users/jhr/.m2/repository/com/google/appengine/appengine-java-sdk/1.8.7/appengine-java-sdk-1.8.7
    </gae.home>
    <datanucleus.version>3.1.2</datanucleus.version>
</properties>

<dependency>
    <groupId>com.google.appengine.orm</groupId>
    <artifactId>datanucleus-appengine</artifactId>
    <version>2.1.2</version>
</dependency>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>${datanucleus.version}</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jpa</artifactId>
    <version>${datanucleus.version}</version>
</dependency>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-cache</artifactId>
    <version>${datanucleus.version}</version>
</dependency>

WEB-INF/lib

-rw-r--r--  1 jhr  staff   249K Nov 16 03:07 datanucleus-api-jpa-3.1.4.jar
-rw-r--r--  1 jhr  staff   338K May 17  2013 datanucleus-appengine-2.1.2.jar
-rw-r--r--  1 jhr  staff    44K Dec  4 00:24 datanucleus-cache-3.1.2.jar
-rw-r--r--  1 jhr  staff   1.7M Nov 16 03:07 datanucleus-core-3.1.4.jar
-rw-r--r--  1 jhr  staff   188K Mar 14  2013 datanucleus-enhancer-3.1.1.jar
-rw-r--r--  1 jhr  staff   7.9K Dec  4 01:22 jsr107cache-1.1.jar

What do I have to add/delete/modify to get this to work?

1

There are 1 answers

0
David Geiger On

As stated in the answer you referenced, App Engine implements the 'old' JSR107 interface, which Datanucleus 3.1+ supports by setting the following property in persistence.xml / jdoconfig.xml:

<property name="datanucleus.cache.level2.type" value="jcache" />

(See http://www.datanucleus.org/products/accessplatform/jpa/cache.html#jcache)

You also need to add the following Maven dependencies:

<!-- JSR 107 API -->
<dependency>
    <groupId>net.sf.jsr107cache</groupId>
    <artifactId>jsr107cache</artifactId>
    <version>1.1</version>
</dependency>
<!-- App Engine Memcache JSR 107 implementation -->
<dependency>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-jsr107cache</artifactId>
    <version>${appengine.target.version}</version>
</dependency>
<!-- Datanucleus cache extension to use a JSR 107 implementation as L2 cache -->
<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-cache</artifactId>
    <version>3.1.3</version>
</dependency>

Based on the information you provided, you were probably lacking the second one?