我正在使用帶有JPA註釋的Google應用程序引擎;如何解決java.io.NotSerializableException:com.google.appengine.datanucleus.query.JPQLQuery?
我有一類
@Entity
public class XYZ implements Serializable{
// default constructor and properties defined here.
}
@SuppressWarnings("unchecked")
public List<XYZ> listXYZ(String id) {
List<XYZ> xyzlist = null;
EntityManager em = EMF.get().createEntityManager();
try{
// Read the existing entries
Query q = em.createQuery("select t from XYZ t where t.id = :id");
q.setParameter("id", id);
xyzlist = q.getResultList();
}catch(Exception e){
}finally{
em.close();
}
return xyzlist ;
}
我得到的對象名單從listXYZ()函數。
List<XYZ> list = dao.listXYZ("1");
,但是當我準備把它變成會議
session.setAttribute("list",list);
它拋出運行時異常:
Caused by: java.io.NotSerializableException: com.google.appengine.datanucleus.query.JPQLQuery$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.writeObject(ObjectOutputStream.java:346)
at com.google.appengine.tools.development.SerializableObjectsOnlyHashSessionManager$SerializableObjectsOnlyHttpSession.checkCanSerialize(SerializableObjectsOnlyHashSessionManager.java:64)
... 40 more
我怎樣才能解決這個問題? 謝謝...
我做調試。它返回的對象。 –
我相信它的確如此,但結果必須是可序列化的。你能分享查詢路徑(導入路徑)嗎? – codelovesme