无法初始化类com.sample.PMF(Google应用引擎)

时间:2010-07-29 13:46:32

标签: java google-cloud-datastore jdo persistence-manager

我在尝试将内容保存到数据存储区时遇到此错误。 我试图搜索但没有得到任何东西。 这是我保存到数据存储区的代码:

    Student temp = null;
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
        Student stu = new Student(name);
        temp = pm.makePersistent(stu);
    } finally {
        pm.close();
    }
    return temp;

有任何关于此的信息表示赞赏!

编辑:添加堆栈跟踪:

at com.sample.dbops.DBManager.saveStudent(DBManager.java:18)     在org.apache.jsp.index_jsp._jspService(index_jsp.java:64)     在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:806)     在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)     在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)     在com.google.appengine.tools.development.PrivilegedJspServlet.access $ 101(PrivilegedJspServlet.java:23)     在com.google.appengine.tools.development.PrivilegedJspServlet $ 2.run(PrivilegedJspServlet.java:59)     at java.security.AccessController.doPrivileged(Native Method)     在com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java:57)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:806)     在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)     在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)     在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)     在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)     在com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)     在org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:268)     在org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)     在com.google.appengine.tools.development.StaticFileUtils.serveWelcomeFileAsForward(StaticFileUtils.java:80)     在com.google.appengine.tools.development.LocalResourceFileServlet.maybeServeWelcomeFile(LocalResourceFileServlet.java:251)     在com.google.appengine.tools.development.LocalResourceFileServlet.doGet(LocalResourceFileServlet.java:117)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:693)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:806)     在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1093)     在com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1084)     在com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:124)     在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1084)     在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)     在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)     在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)     在com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)     在com.google.appengine.tools.development.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:313)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)     在org.mortbay.jetty.Server.handle(Server.java:313)     在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)     在org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:830)     在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)     在org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)     在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)     在org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)     在org.mortbay.thread.BoundedThreadPool $ PoolThread.run(BoundedThreadPool.java:442)

2 个答案:

答案 0 :(得分:1)

堆栈跟踪没有多大帮助,但是没有初始化PersistenceManagerFactory的一个原因是它无法找到您在JDOHelper.getPersistenceManagerFactory(String)方法中指定的持久性单元。

e.g。如果您的PMF的get()方法如下所示:

public static synchronized PersistenceManagerFactory get() {
    if(pmfInstance == null)  {
        pmfInstance = JDOHelper.getPersistenceManagerFactory(
              "transactions-optional");
    }
    return pmfInstance;
}

然后,您的类路径中必须有一个jdoconfig.xml(例如WEB-INF / classes),它定义了一个持久性单元,如下所示:(与您在getPersistenceManagerFactory中使用的名称相同)。在这种情况下,“交易 - 可选”

    <persistence-manager-factory name="transactions-optional">
        <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
        <property name="javax.jdo.option.ConnectionURL" value="appengine"/>
        <property name="javax.jdo.option.NontransactionalRead" value="true"/>
        <property name="javax.jdo.option.NontransactionalWrite" value="false"/>
    </persistence-manager-factory>

答案 1 :(得分:0)

解决:我从一个静态方法调用上面的代码,现在我把它作为一个实例方法,它工作。 但仍然困惑?