Search in sources :

Example 1 with BasicTestEntity1

use of org.hibernate.envers.test.integration.basic.BasicTestEntity1 in project hibernate-orm by hibernate.

the class HasChangedManualFlush method testHasChangedOnDoubleFlush.

@Test
public void testHasChangedOnDoubleFlush() {
    List list = queryForPropertyHasChanged(BasicTestEntity1.class, id, "str1");
    assertEquals(2, list.size());
    assertEquals(makeList(1, 2), extractRevisionNumbers(list));
    list = queryForPropertyHasChanged(BasicTestEntity1.class, id, "long1");
    assertEquals(2, list.size());
    assertEquals(makeList(1, 2), extractRevisionNumbers(list));
}
Also used : List(java.util.List) TestTools.makeList(org.hibernate.envers.test.tools.TestTools.makeList) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1) Test(org.junit.Test)

Example 2 with BasicTestEntity1

use of org.hibernate.envers.test.integration.basic.BasicTestEntity1 in project hibernate-orm by hibernate.

the class HasChangedManualFlush method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    BasicTestEntity1 entity = new BasicTestEntity1("str1", 1);
    em.persist(entity);
    em.getTransaction().commit();
    id = entity.getId();
    // Revision 2 - both properties (str1 and long1) should be marked as modified.
    em.getTransaction().begin();
    entity = em.find(BasicTestEntity1.class, entity.getId());
    entity.setStr1("str2");
    entity = em.merge(entity);
    em.flush();
    entity.setLong1(2);
    entity = em.merge(entity);
    em.flush();
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with BasicTestEntity1

use of org.hibernate.envers.test.integration.basic.BasicTestEntity1 in project hibernate-orm by hibernate.

the class ModifiedFlagSuffix method addNewEntity.

private Integer addNewEntity(String str, long lng) {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng);
    em.persist(bte1);
    em.getTransaction().commit();
    return bte1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1)

Example 4 with BasicTestEntity1

use of org.hibernate.envers.test.integration.basic.BasicTestEntity1 in project hibernate-orm by hibernate.

the class HasChangedNullProperties method addNewEntity.

private Integer addNewEntity(String str, long lng) {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng);
    em.persist(bte1);
    em.getTransaction().commit();
    return bte1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1)

Example 5 with BasicTestEntity1

use of org.hibernate.envers.test.integration.basic.BasicTestEntity1 in project hibernate-orm by hibernate.

the class ModifiedFlagSuffix method testHasChanged.

@Test
public void testHasChanged() throws Exception {
    List list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, id1, "str1");
    assertEquals(1, list.size());
    assertEquals(makeList(1), extractRevisionNumbers(list));
    list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class, id1, "long1");
    assertEquals(1, list.size());
    assertEquals(makeList(1), extractRevisionNumbers(list));
    list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true).add(AuditEntity.property("str1").hasChanged()).add(AuditEntity.property("long1").hasChanged()).getResultList();
    assertEquals(1, list.size());
    assertEquals(makeList(1), extractRevisionNumbers(list));
}
Also used : List(java.util.List) TestTools.makeList(org.hibernate.envers.test.tools.TestTools.makeList) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1) Test(org.junit.Test)

Aggregations

BasicTestEntity1 (org.hibernate.envers.test.integration.basic.BasicTestEntity1)7 EntityManager (javax.persistence.EntityManager)4 Test (org.junit.Test)4 List (java.util.List)3 TestTools.makeList (org.hibernate.envers.test.tools.TestTools.makeList)3 Priority (org.hibernate.envers.test.Priority)1