private void doSerializationTest(boolean auto) throws Exception {
enhance();
Map props = new HashMap();
props.put("openjpa.DetachState", "DetachedStateField=true");
OpenJPAEntityManagerFactory factory =
(OpenJPAEntityManagerFactory) getEmf(props);
OpenJPAEntityManager pm =
(OpenJPAEntityManager) factory.createEntityManager();
startTx(pm);
DetachSMPC pc = new DetachSMPC();
pc.setIntField(1);
DetachSMPC rel = new DetachSMPC();
rel.setIntField(2);
pc.getRelSet().add(rel);
pc.getStringIntMap().put("a", new Integer(99));
pm.persist(pc);
endTx(pm);
Object pcoid = pm.getObjectId(pc);
endEm(pm);
pm = (OpenJPAEntityManager) factory.createEntityManager();
pc = (DetachSMPC) pm.find(DetachSMPC.class, pcoid);
pc.getRelSet();
pc.getStringIntMap();
if (!auto) {
pc = (DetachSMPC) pm.detach(pc);
assertDetachedSM(pc);
}
pc = (DetachSMPC) roundtrip(pc, false);
assertDetachedSM(pc);
endEm(pm);
assertDetachedSM(pc);
assertSize(1, pc.getRelSet());
assertEquals(1, pc.getStringIntMap().size());
pc.setIntField(3);
((DetachSMPC) pc.getRelSet().iterator().next()).setIntField(4);
pc.getStringIntMap().put("b", new Integer(100));
pc = (DetachSMPC) roundtrip(pc, false);
assertDetachedSM(pc);
assertEquals(3, pc.getIntField());
assertSize(1, pc.getRelSet());
//assertDetachedSM (b.getDs ().iterator ().next ());
assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
.getIntField());
assertEquals(new Integer(100), pc.getStringIntMap().get("b"));
pm = (OpenJPAEntityManager) factory.createEntityManager();
startTx(pm);
pc = (DetachSMPC) pm.merge(pc);
assertEquals(3, pc.getIntField());
assertSize(1, pc.getRelSet());
assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
.getIntField());
assertEquals(2, pc.getStringIntMap().size());
assertEquals(new Integer(100), pc.getStringIntMap().get("b"));
endTx(pm);
endEm(pm);
pm = (OpenJPAEntityManager) factory.createEntityManager();
pc = (DetachSMPC) pm.find(DetachSMPC.class, pcoid);
assertEquals(3, pc.getIntField());
assertSize(1, pc.getRelSet());
assertEquals(4, ((DetachSMPC) pc.getRelSet().iterator().next())
.getIntField());
assertEquals(2, pc.getStringIntMap().size());
assertEquals(new Integer(100), pc.getStringIntMap().get("b"));
startTx(pm);
deleteAll(DetachSMPC.class, pm);
endTx(pm);
endEm(pm);
factory.close();
}