此分离实体在合并后不会保存到数据存储区。我已经尝试了几十个没有运气的技巧。解决方案是JDO还是原始数据存储API?无论我等多久,它都无法保存。
EntityManager em = EMF.get().createEntityManager();
em.getTransaction().begin();
OnixUser s = admin.get(0);
if (s.id == null) {
em.persist(s);
em.getTransaction().commit();
}
else {
log.info("email:" + s.email + ", isAdmin:" + s.isAdmin + ", id:" + s.id + ", state:" + NucleusJPAHelper.getObjectState(s));
OnixUser merged = em.merge(s);
log.info("merged... email:" + merged.email + ", isAdmin:" + merged.isAdmin + ", id:" + merged.id + ", state:" + NucleusJPAHelper.getObjectState(merged));
em.persist(merged); //// TRIED WITH & WITHOUT PERSIST
log.info("persisted... email:" + merged.email + ", isAdmin:" + merged.isAdmin + ", id:" + merged.id + ", state:" + NucleusJPAHelper.getObjectState(merged));
em.flush();
log.info("flushed... email:" + merged.email + ", isAdmin:" + merged.isAdmin + ", id:" + merged.id + ", state:" + NucleusJPAHelper.getObjectState(merged));
em.getTransaction().commit();
em.refresh(merged);
/////// THIS IS WHERE IT FAILS isAdmin reverts back to 0.
log.info("refreshed... email:" + merged.email + ", isAdmin:" + merged.isAdmin + ", id:" + merged.id + ", state:" + NucleusJPAHelper.getObjectState(merged));
}
em.close();
Oct 16, 2013 10:25:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: email:chloe@example.com, isAdmin:1, id:4793870697103360, state:detached
Oct 16, 2013 10:25:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: merged... email:chloe@example.com, isAdmin:1, id:4793870697103360, state:persistent
Oct 16, 2013 10:25:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: persisted... email:chloe@example.com, isAdmin:1, id:4793870697103360, state:persistent
Oct 16, 2013 10:25:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: flushed... email:chloe@example.com, isAdmin:1, id:4793870697103360, state:persistent
Oct 16, 2013 10:25:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: refreshed... email:chloe@example.com, isAdmin:0, id:4793870697103360, state:persistent
.level=FINEST
DataNucleus.level=FINEST
Oct 17, 2013 12:36:34 PM com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection <init>
FINE: Created ManagedConnection using DatastoreService = com.google.appengine.api.datastore.DatastoreServiceImpl@470d08b4
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection
FINE: Connection added to the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@58de89bb for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@61478c16]
Oct 17, 2013 12:36:34 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: email:chloe@example.com, isAdmin:1, id:6394759627145216, state:detached
Oct 17, 2013 12:36:34 PM org.datanucleus.state.LifeCycleState changeState
FINE: Object "com.example.sdm.shared.OnixUser@636a0148" (id="com.example.sdm.shared.OnixUser:6394759627145216") has a lifecycle change : "P_CLEAN"->"P_NONTRANS"
Oct 17, 2013 12:36:34 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: merged... email:chloe@example.com, isAdmin:1, id:6394759627145216, state:persistent
Oct 17, 2013 12:36:34 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: persisted... email:chloe@example.com, isAdmin:1, id:6394759627145216, state:persistent
Oct 17, 2013 12:36:34 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: flushed... email:chloe@example.com, isAdmin:1, id:6394759627145216, state:persistent
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl$1 managedConnectionPostClose
FINE: Connection removed from the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@58de89bb for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@61478c16]
Oct 17, 2013 12:36:34 PM com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection <init>
FINE: Created ManagedConnection using DatastoreService = com.google.appengine.api.datastore.DatastoreServiceImpl@1c00f18e
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection
FINE: Connection added to the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@1f2afff for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:nontx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@4949a70e]
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection
FINE: Connection found in the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@1f2afff for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:nontx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@4949a70e]
Oct 17, 2013 12:36:34 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: refreshed... email:chloe@example.com, isAdmin:0, id:6394759627145216, state:persistent
Oct 17, 2013 12:36:34 PM org.datanucleus.state.LifeCycleState changeState
FINE: Object "com.example.sdm.shared.OnixUser@636a0148" (id="com.example.sdm.shared.OnixUser:6394759627145216") has a lifecycle change : "P_NONTRANS"->"DETACHED_CLEAN"
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl closeAllConnections
FINE: Connection found in the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@1f2afff for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:nontx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@4949a70e] but owner object closing so closing connection
Oct 17, 2013 12:36:34 PM org.datanucleus.store.connection.ConnectionManagerImpl$1 managedConnectionPostClose
FINE: Connection removed from the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@1f2afff for key=org.datanucleus.ObjectManagerImpl@3e3ad48 in factory=ConnectionFactory:nontx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@4949a70e]
Oct 17, 2013 12:36:34 PM com.google.apphosting.utils.jetty.AppEngineAuthentication$AppEngineUserRealm disassociate
FINE: Ignoring disassociate call for: chloe@example.com
datanucleus-api-jpa-3.1.3.jar,appengine-api-1.0-sdk-1.8.5.jar