Search in sources :

Example 1 with IntTestEntity

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

the class Simple method testHistoryOfId1.

@Test
public void testHistoryOfId1() {
    IntTestEntity ver1 = new IntTestEntity(10, id1);
    IntTestEntity ver2 = new IntTestEntity(20, id1);
    Assert.assertEquals(ver1, getAuditReader().find(IntTestEntity.class, id1, 1));
    Assert.assertEquals(ver2, getAuditReader().find(IntTestEntity.class, id1, 2));
}
Also used : IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test)

Example 2 with IntTestEntity

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

the class QueryCache method testCacheFindAfterEntitiesAtRevisionQuery.

@Test
public void testCacheFindAfterEntitiesAtRevisionQuery() {
    IntTestEntity entFromQuery = (IntTestEntity) getAuditReader().createQuery().forEntitiesAtRevision(IntTestEntity.class, 1).getSingleResult();
    IntTestEntity entFromFind = getAuditReader().find(IntTestEntity.class, id1, 1);
    assert entFromFind == entFromQuery;
}
Also used : IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test)

Example 3 with IntTestEntity

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

the class OrderByLimitQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    IntTestEntity ite1 = new IntTestEntity(12);
    IntTestEntity ite2 = new IntTestEntity(5);
    IntTestEntity ite3 = new IntTestEntity(8);
    IntTestEntity ite4 = new IntTestEntity(1);
    em.persist(ite1);
    em.persist(ite2);
    em.persist(ite3);
    em.persist(ite4);
    id1 = ite1.getId();
    id2 = ite2.getId();
    id3 = ite3.getId();
    id4 = ite4.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    IntTestEntity ite5 = new IntTestEntity(3);
    em.persist(ite5);
    id5 = ite5.getId();
    ite1 = em.find(IntTestEntity.class, id1);
    ite1.setNumber(0);
    ite4 = em.find(IntTestEntity.class, id4);
    ite4.setNumber(15);
    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 4 with IntTestEntity

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

the class AggregateQuery method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    IntTestEntity ite1 = new IntTestEntity(2);
    IntTestEntity ite2 = new IntTestEntity(10);
    em.persist(ite1);
    em.persist(ite2);
    Integer id1 = ite1.getId();
    Integer id2 = ite2.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    IntTestEntity ite3 = new IntTestEntity(8);
    UnusualIdNamingEntity uine1 = new UnusualIdNamingEntity("id1", "data1");
    em.persist(uine1);
    em.persist(ite3);
    ite1 = em.find(IntTestEntity.class, id1);
    ite1.setNumber(0);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ite2 = em.find(IntTestEntity.class, id2);
    ite2.setNumber(52);
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) UnusualIdNamingEntity(org.hibernate.envers.test.entities.ids.UnusualIdNamingEntity) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with IntTestEntity

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

the class JtaTransaction method initData.

@Test
@Priority(10)
public void initData() throws Exception {
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    EntityManager em;
    IntTestEntity ite;
    try {
        em = getEntityManager();
        ite = new IntTestEntity(10);
        em.persist(ite);
        id1 = ite.getId();
    } finally {
        TestingJtaPlatformImpl.tryCommit();
    }
    em.close();
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    try {
        em = getEntityManager();
        ite = em.find(IntTestEntity.class, id1);
        ite.setNumber(20);
    } finally {
        TestingJtaPlatformImpl.tryCommit();
    }
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

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