Search in sources :

Example 31 with StrTestEntity

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

the class CustomPropertyAccess method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    timestamp1 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    id = te.getId();
    em.getTransaction().commit();
    timestamp2 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 2
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("y");
    em.getTransaction().commit();
    timestamp3 = System.currentTimeMillis();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 32 with StrTestEntity

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

the class DifferentDBSchemaTest method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity ste = new StrTestEntity("x");
    em.persist(ste);
    steId = ste.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ste = em.find(StrTestEntity.class, steId);
    ste.setStr("y");
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 33 with StrTestEntity

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

the class ExceptionListener method testTransactionRollback.

@Test(expected = RuntimeException.class)
public void testTransactionRollback() throws InterruptedException {
    // Trying to persist an entity - however the listener should throw an exception, so the entity
    // shouldn't be persisted
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test)

Example 34 with StrTestEntity

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

the class Inherited method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    timestamp1 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity te = new StrTestEntity("x");
    em.persist(te);
    id = te.getId();
    em.getTransaction().commit();
    timestamp2 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 2
    em.getTransaction().begin();
    te = em.find(StrTestEntity.class, id);
    te.setStr("y");
    em.getTransaction().commit();
    timestamp3 = System.currentTimeMillis();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 35 with StrTestEntity

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

the class BasicJoinColumnSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    EntityManager entityManager = getEntityManager();
    entityManager.getTransaction().begin();
    StrTestEntity str1 = entityManager.find(StrTestEntity.class, str1_id);
    StrTestEntity str2 = entityManager.find(StrTestEntity.class, str2_id);
    entityManager.getTransaction().commit();
    SetJoinColumnRefCollEntity rev1 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 1);
    SetJoinColumnRefCollEntity rev2 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 2);
    SetJoinColumnRefCollEntity rev3 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 3);
    SetJoinColumnRefCollEntity rev4 = getAuditReader().find(SetJoinColumnRefCollEntity.class, coll1_id, 4);
    assert rev1.getCollection().equals(TestTools.makeSet(str1));
    assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
    assert rev3.getCollection().equals(TestTools.makeSet(str2));
    assert rev4.getCollection().equals(TestTools.makeSet());
    assert "coll1".equals(rev1.getData());
    assert "coll1".equals(rev2.getData());
    assert "coll1".equals(rev3.getData());
    assert "coll1".equals(rev4.getData());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) SetJoinColumnRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetJoinColumnRefCollEntity) Test(org.junit.Test)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)102 Test (org.junit.Test)98 EntityManager (javax.persistence.EntityManager)50 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 TestForIssue (org.hibernate.testing.TestForIssue)4 ManyToOneComponent (org.hibernate.envers.test.entities.components.relations.ManyToOneComponent)3 ManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity)3 OneToManyComponent (org.hibernate.envers.test.entities.components.relations.OneToManyComponent)3 OneToManyComponentTestEntity (org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity)3 SortedSetEntity (org.hibernate.envers.test.entities.manytomany.SortedSetEntity)3 ListUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity)3 SetUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity)3 List (java.util.List)2 RevisionType (org.hibernate.envers.RevisionType)2 JoinTableEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity)2 MapUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity)2