use of org.datanucleus.samples.models.hashsetcollection.Circon in project tests by datanucleus.
the class AttachDetachTest method testCircularDetach.
/**
* Test of detaching object graph with circular references
*/
public void testCircularDetach() {
PersistenceManager pm = newPM();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Master m = new Master();
m.setId("tcMaster");
Detail d = new Detail();
d.setId("tcDetail");
Circon c = new Circon();
c.setId("tcConnector");
m.addDetail(d);
m.setCircon(c);
d.setMaster(m);
d.addCircon(c);
c.setDetail(d);
c.addMaster(m);
pm.makePersistent(m);
assertTrue(JDOHelper.isPersistent(m));
assertTrue(JDOHelper.isPersistent(d));
assertTrue(JDOHelper.isPersistent(c));
pm.getFetchPlan().addGroup("all");
pm.getFetchPlan().setMaxFetchDepth(2);
Master dm = (Master) pm.detachCopy(m);
assertTrue(JDOHelper.isDetached(dm));
assertTrue(JDOHelper.isDetached(dm.getCircon()));
assertTrue(JDOHelper.isDetached(dm.getCircon().getDetail()));
tx.rollback();
} catch (JDOUserException ue) {
LOG.error("Exception in test", ue);
fail("Exception thrown while performing test : " + ue.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations