2

What am I missing in the following configuration that my Datanucleus JPA 2 Level 2 cache is not using Google App Engine Memcache service? I am using the GAE 1.7.2 SDK.

In the persistence.xml:

<persistence-unit name="transactions-optional">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
        <property name="datanucleus.appengine.datastoreReadConsistency" value="EVENTUAL" />
        <property name="javax.persistence.query.timeout" value="5000" />
        <property name="datanucleus.datastoreWriteTimeout" value="10000" />
        <property name="datanucleus.singletonEMFForName" value="true"/>
        <property name="datanucleus.cache.level2.cacheName" value="someName"/>
        <property name="datanucleus.cache.level2.type" value="javax.cache"/>
    </properties>
</persistence-unit>

Entity annotations contain:

@Entity
@Cacheable(true)

My WEB-INF/lib looks like this:

-rw-r--r--   1 501  20    27M Oct  3 16:13 appengine-api-1.0-sdk-1.7.2.jar
-rw-r--r--   1 501  20   3.3M Oct  3 16:13 appengine-api-labs.jar
-rw-r--r--   1 501  20   5.0M Oct  3 16:13 appengine-endpoints.jar
-rw-r--r--   1 501  20   6.8K Oct  3 16:13 appengine-jsr107cache-1.7.2.jar
-rw-r--r--   1 501  20    45K Oct  3 16:13 asm-4.0.jar
-rw-r--r--   1 501  20   309K Oct  3 16:13 datanucleus-api-jdo-3.1.0-m3.jar
-rw-r--r--   1 501  20   246K Oct  3 16:13 datanucleus-api-jpa-3.1.0-m3.jar
-rw-r--r--   1 501  20   331K Oct  3 16:13 datanucleus-appengine-2.1.0-final.jar
-rw-r--r--   1 501  20   1.6M Oct  3 16:13 datanucleus-core-3.1.0-m5.jar
-rw-r--r--   1 501  20   112K Oct  3 16:13 geronimo-jpa_2.0_spec-1.0.jar
-rw-r--r--   1 501  20   5.2M Oct  3 16:13 gwt-servlet.jar
-rw-r--r--   1 501  20   196K Oct  3 16:13 jdo-api-3.0.1.jar
-rw-r--r--   1 501  20   7.9K Oct  3 16:13 jsr107cache-1.1.jar
-rw-r--r--   1 501  20    15K Oct  3 16:13 jta-1.1.jar

In the WEB-INF/lib directory, running:

for i in *.jar; do echo $i; jar -tf $i | grep Level2; done

yields:

appengine-api-1.0-sdk-1.7.2.jar
appengine-api-labs.jar
appengine-endpoints.jar
appengine-jsr107cache-1.7.2.jar
asm-4.0.jar
datanucleus-api-jdo-3.1.0-m3.jar
datanucleus-api-jpa-3.1.0-m3.jar
datanucleus-appengine-2.1.0-final.jar
datanucleus-core-3.1.0-m5.jar
org/datanucleus/cache/WeakLevel2Cache.class
org/datanucleus/cache/Level2Cache$PinnedClass.class
org/datanucleus/cache/AbstractLevel2Cache.class
org/datanucleus/cache/SoftLevel2Cache.class
org/datanucleus/cache/Level2Cache.class
org/datanucleus/cache/NullLevel2Cache.class
org/datanucleus/cache/JavaxCacheLevel2Cache.class
geronimo-jpa_2.0_spec-1.0.jar
gwt-servlet.jar
jdo-api-3.0.1.jar
jsr107cache-1.1.jar
jta-1.1.jar

which shows that org.datanucleus.cache.JavaxCacheLevel2Cache is present in datanucleus-core-3.1.0-m5.jar. Yet, when I try to access entities that have been persisted before this cache was enabled, I get the following error on the server side.

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.

Further down the exception stack trace, I find:

Caused by: java.lang.NoClassDefFoundError: javax/cache/Caching
    at org.datanucleus.cache.JavaxCacheLevel2Cache.<init>(JavaxCacheLevel2Cache.java:63)

Now, that is clear but where can I find this javax.cache.Caching? Which JAR should I need to include in the classpath? A cursory Google search does not immediately answer my question.

Thanks.

xtremebytes
  • 173
  • 1
  • 14
  • Added http://repo1.maven.org/maven2/javax/cache/cache-api/0.5/cache-api-0.5.jar. It contains javax.cache.Caching but now I have a different error: ` Caused by: java.lang.IllegalStateException: No CachingProviders found in classpath. ` Is it really this difficult to use the Level 2 cache on the App Engine with JPA (or even JDO)? – xtremebytes Oct 04 '12 at 03:57
  • 2
    I've used GAE with L2 caching via memcached, with DN3.1, and "jcache" with "datanucleus-cache" in the classpath (after looking at other posts in SO) and all works for me – Neil Stockton Oct 05 '12 at 10:39
  • Thanks Neil. Could you confirm the exact datanucleus-cache JAR file that you have used in the war/WEB-INF/lib? Also, do you have a link to it? Which version of the AppEngine SDK did you use? – xtremebytes Oct 09 '12 at 06:20
  • 1
    datanucleus-cache 3.1.1 with GAE 1.7.1 – Neil Stockton Oct 09 '12 at 06:52
  • Okay, will try it out on GAE 1.7.2 (cannot go back to 1.7.1 now) and report back. – xtremebytes Oct 09 '12 at 23:08

1 Answers1

1

Google "memcached" uses an old version of what will become the standard "javax.cache". DataNucleus 3.0 supports only this old version (with properties as you have). DataNucleus 3.1 supports both the old version of javax.cache and the most recent. To use the old version (i.e GAE memcached) with DN 3.1 you need to set the property datanucleus.cache.level2.type to jcache. See http://www.datanucleus.org/products/accessplatform_3_1/jpa/cache.html#jcache

Why you're using DataNucleus version 3.1.0-m3/m5 I've no idea when there are many releases since then!

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • thanks for letting me know. Will try this soon. "Why you're using DataNucleus version 3.1.0-m3/m5 I've no idea when there are many releases since then!" -> because that's the version that was packaged with AppEngine 1.7.2 SDK. I am aware of the newer versions. I simply did not use them because I thought it might generate unforeseen inconsistencies and version incompatibilities with the AppEngine SDK 1.7.2 which is the latest. – xtremebytes Oct 04 '12 at 12:49
  • As a matter of fact, I had indeed tried "jcache" in the past leading to the same problem. I suspect that I am missing some essential JARs. See my first comment to my original question. – xtremebytes Oct 04 '12 at 12:52
  • you mean like "datanucleus-cache" which is clearly mentioned in the link I gave? – DataNucleus Oct 04 '12 at 12:55
  • I've just advised Google of their unwise packaging choices, so hopefully they'll fix it by the next release – DataNucleus Oct 04 '12 at 13:01
  • Actually, I made a mistake in my last comment. When I used "jcache", the error was that "jcache" is not registered and that I needed to check my CLASSPATH. – xtremebytes Oct 04 '12 at 13:15
  • Oh, ok. Noticed your comment now. Will check this and report back! – xtremebytes Oct 04 '12 at 13:16
  • So, is this right? If yes, the error I get now is: Level 2 Cache "jcache" is not registered. Please check your CLASSPATH and specification. org.datanucleus.exceptions.NucleusUserException: Level 2 Cache "jcache" is not registered. Please check your CLASSPATH and specification. – xtremebytes Oct 04 '12 at 13:19
  • And if you meant the cache type should be "datanucleus-cache", then I get the same error: Level 2 Cache "datanucleus-cache" is not registered. Please check your CLASSPATH and specification. org.datanucleus.exceptions.NucleusUserException: Level 2 Cache "datanucleus-cache" is not registered. Please check your CLASSPATH and specification. – xtremebytes Oct 04 '12 at 13:21
  • Thanks for prodding Google. They really ought to get their packaging right. I hope the 1.7.3 will fix it. – xtremebytes Oct 04 '12 at 13:22
  • Sorry for misunderstanding. Ok, so which version of datanucleus-cache should I download? The latest? Would that be fine with the other slightly older JARs in the AppEngine SDK? Is this going to solve the issue with javax.cache.Caching class not found? I could re-download it from http://repo1.maven.org/maven2/javax/cache/cache-api/0.5/cache-api-0.5.jar but then there is the error: Caused by: java.lang.IllegalStateException: No CachingProviders found in classpath. – xtremebytes Oct 04 '12 at 14:38
  • 3.1.x versions of datanucleus-cache go with DN 3.1. All of your errors are caused by not having that in the CLASSPATH – DataNucleus Oct 05 '12 at 04:56
  • As a matter of fact, I did test with datanucleus-cache 3.1.x once and it threw the same error. Perhaps, this was because the rest of the JARs were the old ones packaged with the Google AppEngine SDK? – xtremebytes Oct 05 '12 at 10:33
  • Okay, it is solved now with datanucleus-cache-3.1.1.jar and GAE 1.7.2. Thanks. – xtremebytes Oct 10 '12 at 01:20
  • javax.cache doesn't work in 3.1.1. It complains of missing class: javax.cache.Caching. jcache does work, however. – Martin Dec 03 '12 at 00:42
  • @DataNucleus - could someone please update this answer with the correct stanzas for Maven for GAE SDK 1.8.8 and the required versions for DataNucleus? –  Dec 04 '13 at 06:22
  • DataNucleus documentation for v3.1 is where anyone using DataNucleus should look (what this user is using); we don't go around backdating answers to people's questions on Stackoverflow; that's the point of documentation – DataNucleus Dec 04 '13 at 13:57