Search in sources :

Example 11 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class QueryCache method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite = new IntTestEntity(10);
    em.persist(ite);
    id1 = ite.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ite = em.find(IntTestEntity.class, id1);
    ite.setNumber(20);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 12 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class Simple method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite = new IntTestEntity(10);
    em.persist(ite);
    id1 = ite.getId();
    em.getTransaction().commit();
    em.getTransaction().begin();
    ite = em.find(IntTestEntity.class, id1);
    ite.setNumber(20);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 13 with IntTestEntity

use of org.hibernate.envers.test.entities.IntTestEntity in project hibernate-orm by hibernate.

the class TransactionRollbackBehaviour method testAuditRecordsRollbackBehavior.

private void testAuditRecordsRollbackBehavior(boolean flush, Boolean autoClear) {
    EntityManager entityManager = getEntityManager();
    try {
        if (autoClear != null) {
            entityManager.unwrap(SessionImpl.class).setAutoClear(autoClear);
        }
        // persist and rollback
        entityManager.getTransaction().begin();
        IntTestEntity rollbackEntity = new IntTestEntity(30);
        entityManager.persist(rollbackEntity);
        if (flush) {
            entityManager.flush();
        }
        Integer rollbackId = rollbackEntity.getId();
        entityManager.getTransaction().rollback();
        // persist and commit
        entityManager.getTransaction().begin();
        IntTestEntity commitEntity = new IntTestEntity(50);
        entityManager.persist(commitEntity);
        if (flush) {
            entityManager.flush();
        }
        Integer commitId = commitEntity.getId();
        entityManager.getTransaction().commit();
        List<Number> revisionsForSavedClass = getAuditReader().getRevisions(IntTestEntity.class, commitId);
        assertEquals("There should be one revision for inserted entity.", 1, revisionsForSavedClass.size());
        List<Number> revisionsForRolledbackClass = getAuditReader().getRevisions(IntTestEntity.class, rollbackId);
        assertEquals("There should be no revision for rolled back entity.", 0, revisionsForRolledbackClass.size());
    } finally {
        entityManager.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SessionImpl(org.hibernate.internal.SessionImpl) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity)

Aggregations

IntTestEntity (org.hibernate.envers.test.entities.IntTestEntity)13 Test (org.junit.Test)12 EntityManager (javax.persistence.EntityManager)7 Priority (org.hibernate.envers.test.Priority)6 List (java.util.List)3 UnusualIdNamingEntity (org.hibernate.envers.test.entities.ids.UnusualIdNamingEntity)1 SessionImpl (org.hibernate.internal.SessionImpl)1