use of org.hibernate.envers.test.entities.collection.StringMapEntity in project hibernate-orm by hibernate.
the class HasChangedStringMap method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
StringMapEntity sme1 = new StringMapEntity();
StringMapEntity sme2 = new StringMapEntity();
// Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping)
em.getTransaction().begin();
sme2.getStrings().put("1", "a");
em.persist(sme1);
em.persist(sme2);
em.getTransaction().commit();
// Revision 2 (sme1: adding 2 mappings, sme2: no changes)
em.getTransaction().begin();
sme1 = em.find(StringMapEntity.class, sme1.getId());
sme2 = em.find(StringMapEntity.class, sme2.getId());
sme1.getStrings().put("1", "a");
sme1.getStrings().put("2", "b");
em.getTransaction().commit();
// Revision 3 (sme1: removing an existing mapping, sme2: replacing a value)
em.getTransaction().begin();
sme1 = em.find(StringMapEntity.class, sme1.getId());
sme2 = em.find(StringMapEntity.class, sme2.getId());
sme1.getStrings().remove("1");
sme2.getStrings().put("1", "b");
em.getTransaction().commit();
// No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value)
em.getTransaction().begin();
sme1 = em.find(StringMapEntity.class, sme1.getId());
sme2 = em.find(StringMapEntity.class, sme2.getId());
sme1.getStrings().remove("3");
sme2.getStrings().put("1", "b");
em.getTransaction().commit();
//
sme1_id = sme1.getId();
sme2_id = sme2.getId();
}
Aggregations