title: Datanucleus JPA 2 Level 2 cache in Google AppEngine
body: <p>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.</p>
  
  <p>In the persistence.xml:</p>
  
  <pre><code>&lt;persistence-unit name="transactions-optional"&gt;
      &lt;provider&gt;org.datanucleus.api.jpa.PersistenceProviderImpl&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="datanucleus.NontransactionalRead" value="true"/&gt;
          &lt;property name="datanucleus.NontransactionalWrite" value="true"/&gt;
          &lt;property name="datanucleus.ConnectionURL" value="appengine"/&gt;
          &lt;property name="datanucleus.appengine.datastoreReadConsistency" value="EVENTUAL" /&gt;
          &lt;property name="javax.persistence.query.timeout" value="5000" /&gt;
          &lt;property name="datanucleus.datastoreWriteTimeout" value="10000" /&gt;
          &lt;property name="datanucleus.singletonEMFForName" value="true"/&gt;
          &lt;property name="datanucleus.cache.level2.cacheName" value="someName"/&gt;
          &lt;property name="datanucleus.cache.level2.type" value="javax.cache"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>Entity annotations contain:</p>
  
  <pre><code>@Entity
  @Cacheable(true)
  </code></pre>
  
  <p>My WEB-INF/lib looks like this:</p>
  
  <pre><code>-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
  </code></pre>
  
  <p>In the WEB-INF/lib directory, running:</p>
  
  <pre><code>for i in *.jar; do echo $i; jar -tf $i | grep Level2; done
  </code></pre>
  
  <p>yields:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Further down the exception stack trace, I find:</p>
  
  <pre><code>Caused by: java.lang.NoClassDefFoundError: javax/cache/Caching
      at org.datanucleus.cache.JavaxCacheLevel2Cache.&lt;init&gt;(JavaxCacheLevel2Cache.java:63)
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks.</p>