}
public void testCircularCascadeRefresh ()
{
CascadesEntity ent = new CascadesEntity ();
CascadesEntity rel = new CascadesEntity ();
ent.setAll (rel);
rel.setAll (ent);
OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
startTx(em);
em.persist (ent);
endTx(em);
long id = ent.getId ();
long relId = rel.getId ();
endEm(em);
em = (OpenJPAEntityManager)currentEntityManager();
ent = em.find (CascadesEntity.class, id);
rel = ent.getAll ();
assertEquals (relId, rel.getId ());
assertEquals (ent, rel.getAll ());
startTx(em);
assertNull (ent.getDependent ());
assertNull (rel.getDependent ());
ent.setDependent (new CascadesEntity ());
rel.setDependent (new CascadesEntity ());
em.persist (ent.getDependent ());
em.persist (rel.getDependent ());
em.refresh (ent);
assertNull (ent.getDependent ());
assertNull (rel.getDependent ());
endTx(em);
endEm(em);
em = (OpenJPAEntityManager)currentEntityManager();
ent = em.find (CascadesEntity.class, id);
assertEquals (relId, ent.getAll ().getId ());
assertNull (ent.getDependent ());
assertNull (em.find (CascadesEntity.class, relId).getDependent ());
endEm(em);
ent = new CascadesEntity ();
rel = new CascadesEntity ();
CascadesEntity deep = new CascadesEntity ();
ent.getAllCollection ().add (rel);
rel.getAllCollection ().add (ent);
rel.getAllCollection ().add (deep);
em = (OpenJPAEntityManager)currentEntityManager();
startTx(em);
em.persist (ent);
endTx(em);
id = ent.getId ();
relId = rel.getId ();
long deepId = deep.getId ();
endEm(em);
em = (OpenJPAEntityManager)currentEntityManager();
ent = em.find (CascadesEntity.class, id);
rel = ent.getAllCollection ().iterator ().next ();
assertEquals (relId, rel.getId ());
assertEquals (2, rel.getAllCollection ().size ());
deep = null;
for (CascadesEntity elem : rel.getAllCollection ())
if (elem != ent)
deep = elem;
assertEquals (deepId, deep.getId ());
startTx(em);
assertNull (ent.getDependent ());
assertNull (rel.getDependent ());
assertNull (deep.getDependent ());
ent.setDependent (new CascadesEntity ());
ent.getAllCollection ().add (new CascadesEntity ());
rel.setDependent (new CascadesEntity ());
deep.setDependent (new CascadesEntity ());
em.persistAll (ent.getAllCollection ());
em.persist (ent.getDependent ());
em.persist (rel.getDependent ());
em.persist (deep.getDependent ());
em.refresh (ent);
assertNull (ent.getDependent ());
assertEquals (1, ent.getAllCollection ().size ());
assertTrue (ent.getAllCollection ().contains (rel));
assertNull (rel.getDependent ());
assertEquals (2, rel.getAllCollection ().size ());
assertTrue (rel.getAllCollection ().contains (ent));
assertTrue (rel.getAllCollection ().contains (deep));
assertNull (deep.getDependent ());
endTx(em);
endEm(em);
em = (OpenJPAEntityManager)currentEntityManager();
ent = em.find (CascadesEntity.class, id);