@BeforeClass(dependsOnMethods = "init")
public void initData() {
EntityManager em = getEntityManager();
MapOwnedEntity ed1 = new MapOwnedEntity(1, "data_ed_1");
MapOwnedEntity ed2 = new MapOwnedEntity(2, "data_ed_2");
MapOwningEntity ing1 = new MapOwningEntity(3, "data_ing_1");
MapOwningEntity ing2 = new MapOwningEntity(4, "data_ing_2");
// Revision 1 (ing1: initialy empty, ing2: one mapping)
em.getTransaction().begin();
ing2.getReferences().put("2", ed2);
em.persist(ed1);
em.persist(ed2);
em.persist(ing1);
em.persist(ing2);
em.getTransaction().commit();
// Revision 2 (ing1: adding two mappings, ing2: replacing an existing mapping)
em.getTransaction().begin();
ing1 = em.find(MapOwningEntity.class, ing1.getId());
ing2 = em.find(MapOwningEntity.class, ing2.getId());
ed1 = em.find(MapOwnedEntity.class, ed1.getId());
ed2 = em.find(MapOwnedEntity.class, ed2.getId());
ing1.getReferences().put("1", ed1);
ing1.getReferences().put("2", ed1);
ing2.getReferences().put("2", ed1);
em.getTransaction().commit();
// No revision (ing1: adding an existing mapping, ing2: removing a non existing mapping)
em.getTransaction().begin();
ing1 = em.find(MapOwningEntity.class, ing1.getId());
ing2 = em.find(MapOwningEntity.class, ing2.getId());
ing1.getReferences().put("1", ed1);
ing2.getReferences().remove("3");
em.getTransaction().commit();
// Revision 3 (ing1: clearing, ing2: replacing with a new map)
em.getTransaction().begin();
ing1 = em.find(MapOwningEntity.class, ing1.getId());
ed1 = em.find(MapOwnedEntity.class, ed1.getId());
ing1.getReferences().clear();
ing2.setReferences(new HashMap<String, MapOwnedEntity>());
ing2.getReferences().put("1", ed2);
em.getTransaction().commit();
//
ed1_id = ed1.getId();
ed2_id = ed2.getId();
ing1_id = ing1.getId();
ing2_id = ing2.getId();
}