EntityManager em = getEntityManager();
CollectionRefEdEntity ed1 = new CollectionRefEdEntity(1, "data_ed_1");
CollectionRefEdEntity ed2 = new CollectionRefEdEntity(2, "data_ed_2");
CollectionRefIngEntity ing1 = new CollectionRefIngEntity(3, "data_ing_1", ed1);
CollectionRefIngEntity ing2 = new CollectionRefIngEntity(4, "data_ing_2", ed1);
// Revision 1
em.getTransaction().begin();
em.persist(ed1);
em.persist(ed2);
em.persist(ing1);
em.persist(ing2);
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
ing1 = em.find(CollectionRefIngEntity.class, ing1.getId());
ed2 = em.find(CollectionRefEdEntity.class, ed2.getId());
ing1.setReference(ed2);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
ing2 = em.find(CollectionRefIngEntity.class, ing2.getId());
ed2 = em.find(CollectionRefEdEntity.class, ed2.getId());
ing2.setReference(ed2);
em.getTransaction().commit();
//
ed1_id = ed1.getId();
ed2_id = ed2.getId();
ing1_id = ing1.getId();
ing2_id = ing2.getId();
}