EntityManager em = getEntityManager();
SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2");
SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1", ed1);
SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", ed1);
SetRefIngEntity ing3 = new SetRefIngEntity(5, "data_ing_3", ed1);
SetRefIngEntity ing4 = new SetRefIngEntity(6, "data_ing_4", ed1);
// Revision 1
em.getTransaction().begin();
em.persist(ed1);
em.persist(ed2);
em.persist(ing1);
em.persist(ing2);
em.persist(ing3);
em.persist(ing4);
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
ing1 = em.find(SetRefIngEntity.class, ing1.getId());
ing1.setReference(null);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
ing2 = em.find(SetRefIngEntity.class, ing2.getId());
em.remove(ing2);
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
ing3 = em.find(SetRefIngEntity.class, ing3.getId());
ed2 = em.find(SetRefEdEntity.class, ed2.getId());
ing3.setReference(ed2);
em.getTransaction().commit();
// Revision 5
em.getTransaction().begin();
ing4 = em.find(SetRefIngEntity.class, ing4.getId());
ed1 = em.find(SetRefEdEntity.class, ed1.getId());
em.remove(ed1);
ing4.setReference(null);
em.getTransaction().commit();
//
ed1_id = ed1.getId();
ed2_id = ed2.getId();
ing1_id = ing1.getId();
ing2_id = ing2.getId();
ing3_id = ing3.getId();
ing4_id = ing4.getId();
}