Question

I'm trying to have datanucleus manage my google cloud sql tables within a Google App Engine java application.

Sadly, I receive the following error message:

org.datanucleus.exceptions.ClassNotResolvedException: Class
"org.datanucleus.store.rdbms.RDBMSStoreManager" was not found 
in the CLASSPATH. Please check your specification and your CLASSPATH.

But let's go with order. Here's my jdoconfig.xml

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">

<persistence-manager-factory name="transactions-optional">
    <property name="javax.jdo.PersistenceManagerFactoryClass"
        value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
    <property name="javax.jdo.option.ConnectionURL" value="appengine" />
    <property name="javax.jdo.option.NontransactionalRead"
        value="true" />
    <property name="javax.jdo.option.NontransactionalWrite"
        value="true" />
    <property name="javax.jdo.option.RetainValues" value="true" />
    <property name="datanucleus.appengine.autoCreateDatastoreTxns"
      value="false" />
    <prop key="javax.jdo.option.Multithreaded">true</prop>
    <property name="datanucleus.cache.level2" value="true" />
    <property name="datanucleus.cache.level2.type" value="none"/>

    <property name="datanucleus.cache.level1.type" value="soft"/>
    <property name="datanucleus.appengine.storageVersion"
                 value="READ_OWNED_CHILD_KEYS_FROM_PARENTS"/>
</persistence-manager-factory>

<persistence-manager-factory name="cloud-sql">
    <property name="javax.jdo.PersistenceManagerFactoryClass"
        value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
    <property name="javax.jdo.option.ConnectionDriverName"
         value="com.mysql.jdbc.GoogleDriver"/>
    <property name="javax.jdo.option.ConnectionUserName" value="root"/>
    <property name="datanucleus.autoCreateSchema" value="true"/>
</persistence-manager-factory>
</jdoconfig>

The two persistence-manager-factory declarations are one for the app engine non-relational datastore, one for google cloud sql.

The exception is thrown during construction of my SQLManager. The constructor states

@Inject
public SQLManager(final NamedQueryProvider queryProvider) {
    super(queryProvider);
    final Map<String, String> properties = new HashMap();
    properties.put("javax.jdo.option.ConnectionURL", getConnectionUrl());
    pmFactory = JDOHelper.getPersistenceManagerFactory(properties,
            "cloud-sql");
}

You can say: you must miss a required jar from the classpath. However, in my pom.xml there is

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-accessplatform-jdo-rdbms</artifactId>
    <version>3.3.4</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-rdbms</artifactId>
    <version>3.2.8</version>
</dependency>

The second artifact is actually unneeded, since is thrown in by the first. I've put it as an initial workaround, but it isn't working.

Anyone has something like an idea? There seems to be no documentation on datanucleus+jdo+cloud sql, but since I'm using it for accessing GAE datastore, I would like to reuse the same for cloud sql.

EDIT

Here's the relevant part of stack trace. Unfortunately, I'm unable to see in log in which jars app engine is looking for.

Class "org.datanucleus.store.rdbms.RDBMSStoreManager" was not found in the CLASSPATH.
Please check your specification and your CLASSPATH.
org.datanucleus.exceptions.ClassNotResolvedException: Class
"org.datanucleus.store.rdbms.RDBMSStoreManager" was not found in the CLASSPATH. Please
check your specification and your CLASSPATH.
at org.datanucleus.JDOClassLoaderResolver.classForName(JDOClassLoaderResolver.java:245)
at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:679)
at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:290)
at org.datanucleus.NucleusContext.createStoreManagerForProperties(NucleusContext.java:410)
at org.datanucleus.NucleusContext.initialise(NucleusContext.java:280)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.freezeConfiguration(JDOPersistenceManagerFactory.java:591)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:326)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at javax.jdo.JDOHelper$16.run(JDOHelper.java:1965)
at java.security.AccessController.doPrivileged(Native Method)
at javax.jdo.JDOHelper.invoke(JDOHelper.java:1960)
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(JDOHelper.java:1128)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:808)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1093)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:960)
at com.mycompany.myproduct.mypackage.SQLManager.<init>(SQLManager.java:24)
Was it helpful?

Solution

The problem was a datanucleus jar versions mismatch.

I was using datanucleus-core, datanucleus-api-jdo etc at version 3.0.*, while datanucleus-rdbms 3.2. I've removed datanucleus-accessplatform-jdo-rdbms dependency, since I realized I didn't need all jars it brings in, and downgraded datanucleus-rdbms to 3.0.10 version. (Seems like datanucleus-appengine plugin is not yet supporting 3.2 series, that's why I preferred downgrade over upgrade).

Now I can connect to cloud sql fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top