我正在使用App Engine。 我正在尝试从DataNucleus / JDO版本v1升级到v2。 (JDO2.0至JDO3.0)
但是我的代码在v2下存在以下问题(在v1中可以正常工作)
1 /查询结果给出nullPointerException。
Query q = pm.newQuery(Company.class, query);
List<Company> companies = (List<Company>) q.execute();
// this should return a non-empty list
for (Company company: companies) -> NullPointerException
2 /保留对象后,出现序列化错误:
public final class PMF {
private static final PersistenceManagerFactory pmfInstance =
JDOHelper.getPersistenceManagerFactory("transactions-optional");
private PMF() { pmfInstance.setDetachAllOnCommit(true); }
public static PersistenceManagerFactory get() { return pmfInstance; }
}
Company company = new Company(...);
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.currentTransaction().begin();
pm.makePersistent(company);
pm.currentTransaction().commit();
// because of setDetachAllOnCommit(true), the object should be detached..
} catch (Exception e) {
} finally {
if (!pm.isClosed()) pm.close();
}
此后,公司的序列化(将其发送给客户端)得到“类型'org.datanucleus.store.types.sco.simple.ArrayList'未包含在可通过此SerializationPolicy进行序列化的类型集中”
我在互联网上找不到任何有关迁移的技巧或经验教训。