Datanucleus JPA 2 Level 2 cache in Google AppEngin

2019-02-19 23:43发布

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.

1条回答
你好瞎i
2楼-- · 2019-02-20 00:25

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!

查看更多
登录 后发表回答