Search in sources :

Example 1 with CustomDataRevEntity

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();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) CustomDataRevEntity(org.hibernate.envers.test.entities.reventity.CustomDataRevEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Priority (org.hibernate.envers.test.Priority)1 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)1 CustomDataRevEntity (org.hibernate.envers.test.entities.reventity.CustomDataRevEntity)1 Test (org.junit.Test)1