问题
I am using App Engine. I'm trying to upgrade from DataNucleus/JDO version v1 to v2. (JDO2.0 to JDO3.0)
My code however has following problems under v2 (and works fine in v1)
1/ The result from a query gives a 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/ After persisting an object, I get a serialization error :
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();
}
After this, serialization of company, sending it to the client gives 'Type 'org.datanucleus.store.types.sco.simple.ArrayList' was not included in the set of types which can be serialized by this SerializationPolicy'
I'm not finding anywhere on the internet tips or lessons learned on this migration.
来源:https://stackoverflow.com/questions/27576049/issues-with-migratiing-from-datanucleus-jdo-version-v1-to-v2