1

I am attempting to connect my android app to my backend endpoints (in Google's App Engine) so that I can store my java objects in Google's datastore. However when I try to initialize the PersistenceManagerFactory object, I get the error seen at the end of this post - The PersistenceManagerFactory class must define a static method.

I am trying to initialize the object using the following code, and note: I do have the library in the classpath.

public static PersistenceManagerFactory InitializePersistanceManagerClass(){
        Properties properties = new Properties();
        properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
        properties.setProperty("javax.jdo.option.ConnectionURL", "appengine");
        properties.setProperty("javax.jdo.option.NontransactionalRead", "true");
        properties.setProperty("javax.jdo.option.NontransactionalWrite", "true");
        properties.setProperty("javax.jdo.option.RetainValues", "true");
        properties.setProperty("datanucleus.appengine.autoCreateDatastoreTxns", "true");
        properties.setProperty("datanucleus.appengine.singletonPMFForName", "true");
        PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
        return pmf;
    }

There is no line number listed in the error, however I am 90% sure the problem lies in the code above, or the class that I am using for the persistenceManagerFactory. The error when this code runs appears below. Any ideas? I really don't understand what the problem is....

   08-23 09:10:31.826    7932-7932/com.myApp.myModule E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myApp.myModule, PID: 7932
    javax.jdo.JDOFatalInternalException: The PersistenceManagerFactory class must define a static method
    PersistenceManagerFactory getPersistenceManagerFactory(Map props).
    The class "org.datanucleus.jdo.JDOPersistenceManagerFactory"
    defines a non-static getPersistenceManagerFactory(Map props) method.
            at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(Unknown Source)
            at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
            at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
            at com.myApp.myModule.forStorage.PMF.<init>(Unknown Source)
            at com.myApp.myModule.Login.onConnected(Unknown Source)
            at wz.a(Unknown Source)
            at rb.e(Unknown Source)
            at rb.d(Unknown Source)
            at rd.onConnected(Unknown Source)
            at wz.a(Unknown Source)
            at wz.a(Unknown Source)
            at wy.a(Unknown Source)
            at wy.a(Unknown Source)
            at wv.b(Unknown Source)
            at wu.handleMessage(Unknown Source)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5872)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
            at dalvik.system.NativeStart.main(Native Method)
    NestedThrowablesStackTrace:
    java.lang.NullPointerException
            at javax.jdo.JDOHelper.forName(Unknown Source)
            at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(Unknown Source)
            at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
            at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
            at com.myApp.myModule.forStorage.PMF.<init>(Unknown Source)
            at com.myApp.myModule.Login.onConnected(Unknown Source)
            at wz.a(Unknown Source)
            at rb.e(Unknown Source)
            at rb.d(Unknown Source)
            at rd.onConnected(Unknown Source)
            at wz.a(Unknown Source)
            at wz.a(Unknown Source)
            at wy.a(Unknown Source)
            at wy.a(Unknown Source)
            at wv.b(Unknown Source)
            at wu.handleMessage(Unknown Source)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5872)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
            at dalvik.system.NativeStart.main(Native Method)
Burkhard
  • 14,596
  • 22
  • 87
  • 108
user198923
  • 489
  • 1
  • 7
  • 19
  • You seem to be using some ancient JDO implementation jar there. org.datanucleus.api.jdo.JDOPersistenceManagerFactory is the class to use, not something referred in old docs of original app engine – Neil Stockton Aug 21 '14 at 13:38
  • thanks, but I am receiving the same error after modifying the code, the error that I receive is: akm: The PersistenceManagerFactory class must define a static method PersistenceManagerFactory getPersistenceManagerFactory(Map props). The class "org.datanucleus.api.jdo.JDOPersistenceManagerFactory" defines a non-static getPersistenceManagerFactory(Map props) method. ,,,,,,,,,,, any other ideas? – user198923 Aug 21 '14 at 13:47
  • Obviously the message is completely wrong, as per https://github.com/datanucleus/datanucleus-api-jdo/blob/master/src/main/java/org/datanucleus/api/jdo/JDOPersistenceManagerFactory.java#L193 so suggest you turn your attention to what software is throwing that exception – Neil Stockton Aug 21 '14 at 14:22
  • hmm. Im not sure where to start looking... I've been struggling with this issue for the last few days. What part of the software should I look at? This seems like it should be a little clearer, as my intention is to make a simple app using appengine... – user198923 Aug 21 '14 at 15:12
  • who knows what "ako.a" is ? some android crap? It throws the exception – Neil Stockton Aug 21 '14 at 18:00
  • and what version of jars are you using? – Neil Stockton Aug 21 '14 at 18:28
  • oh! Maybe it's linked to proguard! Im proguarding my app in development because otherwise it throws a huge error because the number of classes in the associated jars are well over 65k. I will try to "keep" some more classes so that maybe I can drill into this. Thanks – user198923 Aug 22 '14 at 18:47
  • Still having this issue. I am using the latest versions of the jars. One found on datanucleus and for JDO, the most recent one on their site. – user198923 Aug 23 '14 at 13:13
  • Adding a bounty to this question because I haven't been able to solve it for a week/\. The line that breaks the code is still "PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);" – user198923 Aug 23 '14 at 13:14
  • It looks like you're trying to use the `PersistenceManagerFactory` on Android's side, is it the case ? I would expect you to run the persistence code on App Engine's side. – David Aug 23 '14 at 13:41
  • and are you going to let us know the versions of the jars you're using? – Neil Stockton Aug 23 '14 at 14:15
  • I already told you, you should use "org.datanucleus.api.jdo.XXX" yet you post some exception with the ancient class name in it. – Neil Stockton Aug 24 '14 at 10:03
  • This is the error that I am seeing when I use "org.datanucleus.api.jdo.JDOPersistenceManagerFactory" I cannot help it that this error is persisting. jdo-api-3.1-rc1.jar, datanucleus-api-jdo-3.1.3.jar, xml-apis-2.0.2.jar – user198923 Aug 24 '14 at 11:29
  • The only way you can get an error message about "org.datanucleus.jdo.JDOPersistenceManagerFactory" is if you have it in the CLASSPATH, and I already said not to have it there. – Neil Stockton Aug 24 '14 at 13:55
  • its referenced in my build.gradle file, not my libs directory. – user198923 Aug 24 '14 at 14:43
  • and when you remove it from the CLASSPATH? – Neil Stockton Aug 25 '14 at 07:20
  • It doesn't answer your question directly, but you might wish to check out https://code.google.com/p/objectify-appengine/ as it makes Datastore for java really easy. – Les Vogel - Google DevRel Aug 28 '14 at 18:56
  • Do you think the following link would have helped you? http://stackoverflow.com/questions/4185382/how-to-use-jdo-persistence-manager – Ripu Daman Aug 29 '14 at 22:47
  • nope! but thanks anyway – user198923 Sep 01 '14 at 22:27

1 Answers1

1

From the javax/jdo/Bundle.properties, we can see the below definition.
EXC_GetPMFNullPointerException = The PersistenceManagerFactory class must define a static methodPersistenceManagerFactory getPersistenceManagerFactory(Map props). The class "{0}" defines a non-static getPersistenceManagerFactory(Map props) method.

From the javax.jdo.JDOHelper source code, we can deduce that the below error message "The PersistenceManagerFactory class must define a static method PersistenceManagerFactory getPersistenceManagerFactory(Map props). The class org.datanucleus.jdo.JDOPersistenceManagerFactory defines a non-static getPersistenceManagerFactory(Map props) method." is coming from the below code in invokeGetPersistenceManagerFactoryOnImplementation method.

    catch (NullPointerException e) {
throw new JDOFatalInternalException (msg.msg("EXC_GetPMFNullPointerException", pmfClassName), e);} 

This is caused by java.lang.NullPointerException at javax.jdo.JDOHelper.forName(Unknown Source), which is mostly probably coming form Class.forName(name, init, loader);
Anyway, you could modify the javax.jdo.JDOHelper.forName method to add some more traces & print more exception info in it. It's not difficult.
If requried, you tell me the version for "jdo-api", then, I could provide one for you.

Alex Beggs
  • 1,187
  • 2
  • 11
  • 17
jawee
  • 271
  • 2
  • 11
  • Hi, thanks for the response. I am using jdo-api-3.1-rc1.jar, datanucleus-api-jdo-3.1.3.jar, xml-apis-2.0.2.jar. I am currently investigating the JDOHelper source code to see if I can add more code to the error... – user198923 Aug 24 '14 at 11:31
  • Ok, if you need the modified jars, I can provide it for you. FYI. – jawee Aug 25 '14 at 13:14
  • thank you for the help, I have abandoned my implementation and started from scratch... – user198923 Aug 25 '14 at 15:27
  • @user198923 Fine. Good luck! – jawee Aug 26 '14 at 07:41