use of org.hibernate.envers.test.entities.reventity.CustomDataRevEntity in project hibernate-orm by hibernate.
the class CustomNoListener method initData.
@Test
@Priority(10)
public void initData() throws InterruptedException {
EntityManager em = getEntityManager();
// Revision 1
em.getTransaction().begin();
StrTestEntity te = new StrTestEntity("x");
em.persist(te);
id = te.getId();
// Setting the data on the revision entity
CustomDataRevEntity custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
custom.setData("data1");
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
te = em.find(StrTestEntity.class, id);
te.setStr("y");
// Setting the data on the revision entity
custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
custom.setData("data2");
em.getTransaction().commit();
// Revision 3 - no changes, but rev entity should be persisted
em.getTransaction().begin();
// Setting the data on the revision entity
custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, true);
custom.setData("data3");
em.getTransaction().commit();
// No changes, rev entity won't be persisted
em.getTransaction().begin();
// Setting the data on the revision entity
custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
custom.setData("data4");
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
te = em.find(StrTestEntity.class, id);
te.setStr("z");
// Setting the data on the revision entity
custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
custom.setData("data5");
custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
custom.setData("data5bis");
em.getTransaction().commit();
}
Aggregations