EntityManager em = getEntityManager();
StrTestEntity str1 = new StrTestEntity("str1");
StrTestEntity str2 = new StrTestEntity("str2");
MapUniEntity coll1 = new MapUniEntity(3, "coll1");
// Revision 1 (coll1: initialy one mapping)
em.getTransaction().begin();
em.persist(str1);
em.persist(str2);
coll1.setMap(new HashMap<String, StrTestEntity>());
coll1.getMap().put("1", str1);
em.persist(coll1);
em.getTransaction().commit();
// Revision 2 (coll1: adding one mapping)
em.getTransaction().begin();
str2 = em.find(StrTestEntity.class, str2.getId());
coll1 = em.find(MapUniEntity.class, coll1.getId());
coll1.getMap().put("2", str2);
em.getTransaction().commit();
// Revision 3 (coll1: replacing one mapping)
em.getTransaction().begin();
str1 = em.find(StrTestEntity.class, str1.getId());
coll1 = em.find(MapUniEntity.class, coll1.getId());
coll1.getMap().put("2", str1);
em.getTransaction().commit();
// Revision 4 (coll1: removing one mapping)
em.getTransaction().begin();
coll1 = em.find(MapUniEntity.class, coll1.getId());
coll1.getMap().remove("1");
em.getTransaction().commit();
//
str1_id = str1.getId();
str2_id = str2.getId();
coll1_id = coll1.getId();
}