使用GWT和JDO,为什么执行查询总是返回null?

时间:2013-04-05 13:26:32

标签: gwt null google-cloud-datastore jdo

过去几个月我一直在使用GWT,我需要开始工作的最后一件事是将我的应用程序数据存储在带有GAE而不是SQLITE的JDO对象中。 我的应用程序成功将对象(在本例中为论坛主题)保存到数据存储区(我已在appspot / appengine日志查看器中确认了这一点)。当我对主题ID进行硬编码时,我设法获取了其中一个对象:

 pManager.getObjectById(Topic.class, 1);

但是当我尝试使用Query类并获取包含所有主题的List时,我从execute方法得到的所有内容都为null。如果我清除主题的数据存储区,我可以打印结果列表的大小(因此它不应该为空)但是当数据存储区中有主题时,它总是生成List<Topic> null

以下是相关代码:

// Fetches all Topic-objects from the App Engine storage and 
// puts them in an ArrayList that is returned.
public ArrayList<Topic> getAllTopics() {

    ArrayList<Topic> queryResults = new ArrayList<Topic>();
    PersistenceManager pManager = PMF.get().getPersistenceManager();
    pManager.getFetchPlan().setGroup(FetchGroup.ALL);
    Query topicQuery = pManager.newQuery(Topic.class);

    // Does not make any difference what query I use
    //Query topicQuery = pManager.newQuery(Topic.class);

    Topic newTopic = null;
    try {
        System.out.println("Will now try to execute the query...");
        List<Topic> results = (List<Topic>)topicQuery.execute();
        System.out.println("Result size: " + results.size());
        System.out.println("Query now done executing.");
        for (Topic t : results) {
            // Does not seem to make any difference either
            //      newTopic = pManager.detachCopy(t);
            //      queryResults.add(newTopic);
            queryResults.add(t);
        }
        // I can fetch one topic when hard-coding the ID.
        //      queryResults.add(pManager.getObjectById(Topic.class, 1));
    } catch(Exception e) {
        System.out.println("Exception when getting all topics on server: " + e.getMessage() + " - ");
        System.out.print( e.getStackTrace());
    } finally {
        topicQuery.closeAll();
        pManager.close();
    }   


    return queryResults;
}

以下是让主题持续存在的代码:

    // Creates a topic object and stores it in App Engine
// Returns true if it succeeded, otherwise false
public Boolean createTopic(String title_, String text_) {

    PersistenceManager pManager = PMF.get().getPersistenceManager();
    UserAuthImpl newUserAuth = new UserAuthImpl();

    if(newUserAuth.returnUser().isEmpty() || newUserAuth.returnUser() == null ) 
        return false;

    Topic newTopic = new Topic(newUserAuth.returnUser(), title_, text_, new Date(Calendar.getInstance().getTimeInMillis()));

    try {
        // Did not help: pManager.setDetachAllOnCommit(true);
        pManager.makePersistent(newTopic);
    } catch(Exception e) {
        System.out.println("Error while creating topic: " + e.getMessage());
        return false;
    } finally {
        pManager.close();
    }
    return true;
}

这是Topic对象类:

package se.biffnet.tddi15.forum.client;

import java.io.Serializable;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Topic implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
long    topicID;

@Persistent
String  authorID;

@Persistent
String  postTitle;

@Persistent
String  postText;

@Persistent
Date    postDate;

public Topic(String authorID_, String postTitle_, String postText_, 
        java.util.Date date) {
    authorID    = authorID_;
    postTitle   = postTitle_;
    postText    = postText_;
}

public Topic() {
    authorID    = "";
    postTitle   = "";
    postText    = "";
    postDate    = null;
}

public String getPostTitle() {
    return postTitle;
}

public void setPostTitle(String postTitle) {
    this.postTitle = postTitle;
}

public String getPostText() {
    return postText;
}

public void setPostText(String postText) {
    this.postText = postText;
}

public long getTopicID() {
    return topicID;
}

public String getAuthorID() {
    return authorID;
}

public Date getPostDate() {
    return postDate;
    } 
}

所以我猜问题是:
为什么execute()总是返回null?非常感谢=)

EDIT2:必须更改logging.properties才能看到调试消息。这是我的坏事。这里的日志很大,所以这里有一个指向pastebin的链接:http://pastebin.com/CGX1Aug0

EDIT3:异常及其堆栈跟踪:

java.lang.NullPointerException: null
com.google.appengine.datanucleus.query.QueryEntityPKFetchFieldManager.fetchLongField(QueryEntityPKFetchFieldManager.java:74)
org.datanucleus.identity.IdentityUtils.getApplicationIdentityForResultSetRow(IdentityUtils.java:101)
com.google.appengine.datanucleus.EntityUtils.entityToPojo(EntityUtils.java:1011)
com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:229)
com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:226)
com.google.appengine.datanucleus.query.LazyResult.resolveNext(LazyResult.java:96)
com.google.appengine.datanucleus.query.LazyResult$LazyAbstractListIterator.computeNext(LazyResult.java:229)
com.google.appengine.datanucleus.query.AbstractIterator.tryToComputeNext(AbstractIterator.java:131)
com.google.appengine.datanucleus.query.AbstractIterator.hasNext(AbstractIterator.java:126)
com.google.appengine.datanucleus.query.LazyResult$AbstractListIterator.hasNext(LazyResult.java:183)
se.biffnet.tddi15.forum.server.DbHandlerImpl.getAllTopics(DbHandlerImpl.java:75)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:167)
java.security.AccessController.doPrivileged(Native Method)
com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:164)
com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:125)
com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:43)
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:57)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
org.mortbay.jetty.Server.handle(Server.java:326)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:438)
com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:480)
com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)
com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:484)
com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
java.lang.Thread.run(Thread.java:722)

0 个答案:

没有答案