PersistentManagerFactory can not be created in Google App Engine application

511 views
Skip to first unread message

Chuck

unread,
Jul 16, 2018, 2:44:25 PM7/16/18
to Google App Engine
Hello All,

My Google App Engine application tries to create PersistentManagerFactory as follows

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");
    
    private PMF() {}

    public static PersistenceManagerFactory get() {    
        return pmfInstance;
    }
}

The application was compiled successfully in maven. During the execution time, I got the following exception

Caused by: javax.jdo.JDOFatalUserException: A property named javax.jdo.PersistenceManagerFactoryClass must be specified, or a jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath, or a property named javax.jdo.option.PersistenceUnitName must be specified. at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:861) at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1099) at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:919)

Is there a way to create a PersistentManagerFactory?  My code for creating PMF looks like this.


Thanks!
C



Kenworth (Google Cloud Platform)

unread,
Jul 17, 2018, 12:17:26 PM7/17/18
to google-a...@googlegroups.com
A quick lookup shows this seems to be an issue with the file/folder path structure. References:


Unfortunately, this is beyond the scope of Google Groups which is reserved for general discussion of GCP's products and services.For further technical assistance, try Stack Exchange sites. Stack Exchange uses a popular question-and-answer platform and it hosts a number of sites, including StackOverflow. Please visit our community support page for list of StackOverflow tags we monitor.


Chuck

unread,
Jul 19, 2018, 3:12:56 PM7/19/18
to Google App Engine
I still get the error. My PMF class is 

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("datanucleus.properties");
    
    private PMF() {}

    public static PersistenceManagerFactory get() {   
        return pmfInstance;
    }
}

My ./war/WEB-INF/classes/META-INF/jdoconfig.xml is like this

<?xml version="1.0" encoding="utf-8"?>
   xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">

   <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="true"/>
       <property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
       <property name="datanucleus.persistenceByReachabilityAtCommit" value="false"/>
       <property name="javax.jdo.option.PersistenceUnitName" value="true"/>
   </persistence-manager-factory>
</jdoconfig>


And my ./src/main/resources/datanucleus.properties

javax.jdo.option.ConnectionDriverName=org.apache.derby.jdbc.EmbeddedDriver
javax.jdo.option.ConnectionURL=jdbc:derby:RECORDTABLE;create=true
javax.jdo.option.ConnectionUserName=user
javax.jdo.option.ConnectionPassword=password

datanucleus.autoCreateTables=true
datanucleus.autoCreateSchema=true
datanucleus.autoCreateColumns=true
datanucleus.autoCreateConstraints=true
datanucleus.RetainValues=true

I did something wrong in these settings.

George (Cloud Platform Support)

unread,
Jul 20, 2018, 1:51:25 PM7/20/18
to Google App Engine
What is the value of your CLASSPATH environment variable? Is the jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory included in CLASSPATH? 

This discussion group is oriented more towards general opinions, trends and issues of general nature touching the app engine. For coding and programming architecture, you may be better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 

Chuck

unread,
Jul 20, 2018, 3:02:18 PM7/20/18
to Google App Engine
My CLASSPATH returns null value.

System
.getenv("CLASSPATH");

My .bashrc has defined 

export CLASSPATH="/war/WEB-INF/lib"

George (Cloud Platform Support)

unread,
Jul 23, 2018, 10:27:22 AM7/23/18
to Google App Engine
If you are looking at the CLASSPATH at execution time, you get a different value from System.getenv than, let's say, from a browser, your IDE or a console. You may consider using a line such as System.getProperty("java.class.path"); You should make sure that your jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry is present in the CLASSPATH.

It may be appropriate to remind you now that we mean to exchange general opinions here, on trends and on issues of general nature touching the app engine. For coding and programming architecture, you may be better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 

Chuck

unread,
Jul 23, 2018, 5:46:19 PM7/23/18
to Google App Engine
I solved the issue after adding dependency (datanucleus-api-jdo-3.0.0-m5.jar) and movong jdoconfig.xml to /META-INF/

But I encountered another issue.  

Caused by: javax.jdo.JDOUserException: You have either specified for this PMF to use a "persistence-unit" of "xxx" (yet this doesnt exist!) or you called JDOHelper.getPersistenceManagerFactory with "xxx" as the name of a properties file (and this doesnt exist in the CLASSPATH)

In jdoconfig.xml, what VALUE should be used for <property name="javax.jdo.option.PersistenceUnitName" value="xxx"/>?

Does anyone know?

Thanks

George (Cloud Platform Support)

unread,
Jul 24, 2018, 3:53:06 PM7/24/18
to Google App Engine
You don't seem to have set the name of the persistence unit. A method setPersistenceUnitName() is defined to this purpose in Class JDOPersistenceManagerFactory that you imported by means of "javax.jdo.PersistenceManagerFactory; ". 

What do you want to achieve through lines such as: <property name="datanucleus.persistenceByReachabilityAtCommit" value="false"/> and <property name="javax.jdo.option.PersistenceUnitName" value="true"/> in your jdoconfig.xml file? What happens if you follow the relevant examples on the "Using JDO 3.0 with App Engine" documentation page

You might have received more timely and comprehensive answers in a forum such as stackoverflow. This Group is not meant for code debugging. 
Reply all
Reply to author
Forward
0 new messages