@BeforeClass(dependsOnMethods = "init")
public void initData() {
EntityManager em = getEntityManager();
SetOwnedEntity ed1 = new SetOwnedEntity(1, "data_ed_1");
SetOwnedEntity ed2 = new SetOwnedEntity(2, "data_ed_2");
SetOwningEntity ing1 = new SetOwningEntity(3, "data_ing_1");
SetOwningEntity ing2 = new SetOwningEntity(4, "data_ing_2");
// 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(SetOwningEntity.class, ing1.getId());
ing2 = em.find(SetOwningEntity.class, ing2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ing1.setReferences(new HashSet<SetOwnedEntity>());
ing1.getReferences().add(ed1);
ing2.setReferences(new HashSet<SetOwnedEntity>());
ing2.getReferences().add(ed1);
ing2.getReferences().add(ed2);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ing1.getReferences().add(ed2);
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ing1.getReferences().remove(ed1);
em.getTransaction().commit();
// Revision 5
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ing1.setReferences(null);
em.getTransaction().commit();
//
ed1_id = ed1.getId();
ed2_id = ed2.getId();
ing1_id = ing1.getId();
ing2_id = ing2.getId();
}