Search in sources :

Example 1 with AuditedTestEntity

use of org.hibernate.envers.test.integration.auditReader.AuditedTestEntity in project hibernate-orm by hibernate.

the class HasChangedAPITest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    AuditedTestEntity ent1 = new AuditedTestEntity(1, "str1");
    NotAuditedTestEntity ent2 = new NotAuditedTestEntity(1, "str1");
    em.persist(ent1);
    em.persist(ent2);
    em.getTransaction().commit();
    em.getTransaction().begin();
    ent1 = em.find(AuditedTestEntity.class, 1);
    ent2 = em.find(NotAuditedTestEntity.class, 1);
    ent1.setStr1("str2");
    ent2.setStr1("str2");
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) NotAuditedTestEntity(org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity) AuditedTestEntity(org.hibernate.envers.test.integration.auditReader.AuditedTestEntity) NotAuditedTestEntity(org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with AuditedTestEntity

use of org.hibernate.envers.test.integration.auditReader.AuditedTestEntity in project hibernate-orm by hibernate.

the class HasChangedAPITest method testHasChangedHasNotChangedCriteria.

@Test
public void testHasChangedHasNotChangedCriteria() throws Exception {
    List list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).add(AuditEntity.property("str1").hasChanged()).getResultList();
    assertEquals(2, list.size());
    assertEquals("str1", ((AuditedTestEntity) list.get(0)).getStr1());
    assertEquals("str2", ((AuditedTestEntity) list.get(1)).getStr1());
    list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).add(AuditEntity.property("str1").hasNotChanged()).getResultList();
    assertTrue(list.isEmpty());
}
Also used : NotAuditedTestEntity(org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity) AuditedTestEntity(org.hibernate.envers.test.integration.auditReader.AuditedTestEntity) List(java.util.List) Test(org.junit.Test)

Aggregations

AuditedTestEntity (org.hibernate.envers.test.integration.auditReader.AuditedTestEntity)2 NotAuditedTestEntity (org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity)2 Test (org.junit.Test)2 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 Priority (org.hibernate.envers.test.Priority)1