Search in sources :

Example 46 with Priority

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

the class ImplicitMappedByTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    OneToManyOwned owned = new OneToManyOwned("data", null);
    Set<ManyToOneOwning> referencing = new HashSet<ManyToOneOwning>();
    ManyToOneOwning owning1 = new ManyToOneOwning("data1", owned);
    referencing.add(owning1);
    ManyToOneOwning owning2 = new ManyToOneOwning("data2", owned);
    referencing.add(owning2);
    owned.setReferencing(referencing);
    // Revision 1
    em.getTransaction().begin();
    em.persist(owned);
    em.persist(owning1);
    em.persist(owning2);
    em.getTransaction().commit();
    ownedId = owned.getId();
    owning1Id = owning1.getId();
    owning2Id = owning2.getId();
    // Revision 2
    em.getTransaction().begin();
    owning1 = em.find(ManyToOneOwning.class, owning1.getId());
    em.remove(owning1);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    owning2 = em.find(ManyToOneOwning.class, owning2.getId());
    owning2.setData("data2modified");
    em.merge(owning2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) HashSet(java.util.HashSet) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 47 with Priority

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

the class RelationNotAuditedTarget method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
    UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
    // No revision
    em.getTransaction().begin();
    em.persist(uste1);
    em.persist(uste2);
    em.getTransaction().commit();
    // Revision 1
    em.getTransaction().begin();
    uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
    uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
    TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
    TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
    em.persist(tnae1);
    em.persist(tnae2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    tnae1.setReference(uste2);
    tnae2.setReference(uste1);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    //field not changed!!!
    tnae1.setReference(uste2);
    tnae2.setReference(uste2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    tnae1.setReference(uste1);
    tnae2.setReference(uste1);
    em.getTransaction().commit();
    //
    tnae1_id = tnae1.getId();
    tnae2_id = tnae2.getId();
    uste1_id = uste1.getId();
    uste2_id = uste2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) TargetNotAuditedEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 48 with Priority

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

the class AddDelTest method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    Session session = openSession();
    session.getTransaction().begin();
    GivenIdStrEntity entity = new GivenIdStrEntity(1, "data");
    session.persist(entity);
    session.getTransaction().commit();
    // Revision 2
    session.getTransaction().begin();
    // Just to create second revision.
    session.persist(new StrTestEntity("another data"));
    entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1);
    // First try to remove the entity.
    session.delete(entity);
    // Then save it.
    session.save(entity);
    session.getTransaction().commit();
    // Revision 3
    session.getTransaction().begin();
    entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1);
    // First try to remove the entity.
    session.delete(entity);
    // Then change it's state.
    entity.setData("modified data");
    // Finally save it.
    session.save(entity);
    session.getTransaction().commit();
    session.close();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Session(org.hibernate.Session) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 49 with Priority

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

the class DetachedEntityTest method initData.

@Test
@Priority(10)
public void initData() {
    final Session s = openSession();
    try {
        // revision 1 - persist the project entity
        s.getTransaction().begin();
        final Project project = new Project(1, "fooName");
        s.persist(project);
        s.getTransaction().commit();
        // detach the project entity
        s.clear();
        // revision 2 to 6 - update the detached project entity.
        for (int i = 0; i < 5; ++i) {
            s.getTransaction().begin();
            project.setName("fooName" + (i + 2));
            s.update(project);
            s.getTransaction().commit();
            s.clear();
        }
    } catch (Throwable t) {
        if (s.getTransaction().isActive()) {
            s.getTransaction().rollback();
        }
        throw t;
    } finally {
        s.close();
    }
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 50 with Priority

use of org.hibernate.envers.test.Priority 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)

Aggregations

Priority (org.hibernate.envers.test.Priority)268 Test (org.junit.Test)268 EntityManager (javax.persistence.EntityManager)249 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)48 Session (org.hibernate.Session)16 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)12 EmbId (org.hibernate.envers.test.entities.ids.EmbId)8 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)7 Component1 (org.hibernate.envers.test.entities.components.Component1)7 MulId (org.hibernate.envers.test.entities.ids.MulId)7 HashSet (java.util.HashSet)6 IntTestEntity (org.hibernate.envers.test.entities.IntTestEntity)6 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)6 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)6 Component2 (org.hibernate.envers.test.entities.components.Component2)5 ComponentTestEntity (org.hibernate.envers.test.entities.components.ComponentTestEntity)4 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)4 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3