java.io.NotSerializableException:com.google.appengine.datanucleus.query.JDOQLQuery $ 1异常,当使用jdo查询设置List时

时间:2013-06-25 22:01:39

标签: google-app-engine jsf-2 jdo

我正在尝试将jdoql查询的结果显示为a,但得到以下异常: java.io.NotSerializableException:com.google.appengine.datanucleus.query.JDOQLQuery $ 1

该实施使用的是Google App Engine 1.8.0,JSF 2.1.22,JDO 3和Eclipse Juno。 任何建议将不胜感激。谢谢!

这是我的实体:

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

import java.io.Serializable;
import java.util.Date;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class DBF implements Serializable {
    @PrimaryKey
    private String key;

    @Persistent
    private String progName;

    @Persistent
    private String desc;

    @Persistent
    private String path;

    @Persistent
    private Date lastUpdatedDate;

    @Persistent
    private boolean isActive;

    public DBF(String name, String description, String dirPath, Date lastUpdatedOn, boolean active) {
        this.progName = name;
        this.desc = description;
        this.path = dirPath;
        this.lastUpdatedDate = lastUpdatedOn;
        this.isActive = active;
        this.key = path + progName;
    }
.....
getters & setters

这是托管bean:

@ManagedBean
@SessionScoped
public class DBFForm implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private final static Logger logger = Logger.getLogger(DBFForm.class.getName());

    private String name;
    private String description;
    private String path;
    private Date lastUpdated;

    private long dbfListStartRange = 0;
    private long dbfListEndRange = 10;

    private List<DBF> dbfList;

    public DBFForm()
    {
        logger.info("A new DBFForm");
        dbfList = DBFUtils.retrieveAllDBFInRange(dbfListStartRange, dbfListEndRange);

}
.... getters & setters....

这是utils类:

public class DBFUtils {
    private final static Logger logger = Logger.getLogger(DBFUtils.class.getName());
public static List<DBF> retrieveAllDBFInRange(long startRange, long endRange)
    {
        logger.info("Retrieving all DBF in range from " + String.valueOf(startRange) + " to " + String.valueOf(endRange));
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Query q = pm.newQuery(DBF.class);
        q.setOrdering("progName ASC");
        q.setRange(startRange, endRange);

        return (List<DBF>)q.execute();
    }
}
.....

堆栈追踪:

java.lang.RuntimeException: java.io.NotSerializableException: com.google.appengine.datanucleus.query.JDOQLQuery$1
    at com.google.appengine.tools.development.SerializableObjectsOnlyHashSessionManager$SerializableObjectsOnlyHttpSession.checkCanSerialize(SerializableObjectsOnlyHashSessionManager.java:66)
    at com.google.appengine.tools.development.SerializableObjectsOnlyHashSessionManager$SerializableObjectsOnlyHttpSession.setAttribute(SerializableObjectsOnlyHashSessionManager.java:43)
    at com.sun.faces.context.SessionMap.put(SessionMap.java:141)
    at com.sun.faces.context.SessionMap.put(SessionMap.java:61)
    at com.sun.faces.mgbean.BeanManager$ScopeManager$SessionScopeHandler.handle(BeanManager.java:578)
    at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(BeanManager.java:457)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:268)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:112)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIData.getValue(UIData.java:730)
    at javax.faces.component.UIData.getDataModel(UIData.java:1809)
    at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:483)
    at javax.faces.component.UIData.setRowIndex(UIData.java:472)
    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:82)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:850)
    at javax.faces.component.UIData.encodeBegin(UIData.java:1131)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1777)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectRequest(DevAppServerServersFilter.java:369)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectServerRequest(DevAppServerServersFilter.java:352)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:115)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:438)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.io.NotSerializableException: com.google.appengine.datanucleus.query.JDOQLQuery$1
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at java.util.ArrayList.writeObject(ArrayList.java:710)
    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 java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at com.google.appengine.tools.development.SerializableObjectsOnlyHashSessionManager$SerializableObjectsOnlyHttpSession.checkCanSerialize(SerializableObjectsOnlyHashSessionManager.java:64)
    ... 71 more

1 个答案:

答案 0 :(得分:0)

为什么你序列化的东西不清楚(似乎是在HttpSession中序列化所有东西?)。你的“retrieveAllDBFInRange”方法是错误的,它不会关闭“pm”或“查询”(应该在最后)。完成后,如果仍有问题,请将查询结果复制到ArrayList中并从此方法返回