public void testCascadeMergeDetachState2() {
EntityManager em = emf.createEntityManager();
try {
// Create simple bi-di graph
ShipPackage2 p = new ShipPackage2();
Label2 l = new Label2(p);
p.setLabel2(l);
// Persist
em.getTransaction().begin();
em.persist(p);
em.getTransaction().commit();
// Detach
em.clear();
assertFalse(em.contains(l));
assertFalse(em.contains(p));
assertFalse(em.contains(l.getPackage2()));
assertFalse(em.contains(p.getLabel2()));
em.getTransaction().begin();
ShipPackage2 mergedPackage = em.merge(p);
assertFalse(mergedPackage == p);
assertFalse(l == mergedPackage.getLabel2());
// Assert that the bi-directional relationship points to the
// newly merged entity
assertTrue(mergedPackage == mergedPackage.getLabel2().getPackage2());
assertFalse(p == mergedPackage.getLabel2().getPackage2());
em.remove(mergedPackage);
em.getTransaction().commit();
} finally {
if (em != null) {
if (em.getTransaction().isActive())