Search in sources :

Example 71 with Priority

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

the class EntityNamesTest method initData.

@Test
@Priority(10)
public void initData() {
    Person pers1 = new Person("Hernan", 28);
    Person pers2 = new Person("Leandro", 29);
    Person pers3 = new Person("Barba", 32);
    Person pers4 = new Person("Camomo", 15);
    // Revision 1
    getSession().getTransaction().begin();
    List<Person> owners = new ArrayList<Person>();
    owners.add(pers1);
    owners.add(pers2);
    owners.add(pers3);
    Car car1 = new Car(5, owners);
    getSession().persist(car1);
    getSession().getTransaction().commit();
    long person1Id = pers1.getId();
    // Revision 2
    owners = new ArrayList<Person>();
    owners.add(pers2);
    owners.add(pers3);
    owners.add(pers4);
    Car car2 = new Car(27, owners);
    getSession().getTransaction().begin();
    Person person1 = (Person) getSession().get("Personaje", person1Id);
    person1.setName("Hernan David");
    person1.setAge(40);
    getSession().persist(car1);
    getSession().persist(car2);
    getSession().getTransaction().commit();
}
Also used : Car(org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car) ArrayList(java.util.ArrayList) Person(org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 72 with Priority

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

the class TrackingEntitiesMultipleChangesTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - Adding two entities
    em.getTransaction().begin();
    StrTestEntity ste1 = new StrTestEntity("x");
    StrTestEntity ste2 = new StrTestEntity("y");
    em.persist(ste1);
    em.persist(ste2);
    steId1 = ste1.getId();
    steId2 = ste2.getId();
    em.getTransaction().commit();
    // Revision 2 - Adding first and removing second entity
    em.getTransaction().begin();
    ste1 = em.find(StrTestEntity.class, steId1);
    ste2 = em.find(StrTestEntity.class, steId2);
    ste1.setStr("z");
    em.remove(ste2);
    em.getTransaction().commit();
    // Revision 3 - Modifying and removing the same entity.
    em.getTransaction().begin();
    ste1 = em.find(StrTestEntity.class, steId1);
    ste1.setStr("a");
    em.merge(ste1);
    em.remove(ste1);
    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 73 with Priority

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

the class RevisionForDate 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 rfd = new StrTestEntity("x");
    em.persist(rfd);
    id = rfd.getId();
    em.getTransaction().commit();
    timestamp2 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 2
    em.getTransaction().begin();
    rfd = em.find(StrTestEntity.class, id);
    rfd.setStr("y");
    em.getTransaction().commit();
    timestamp3 = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 3
    em.getTransaction().begin();
    rfd = em.find(StrTestEntity.class, id);
    rfd.setStr("z");
    em.getTransaction().commit();
    timestamp4 = 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 74 with Priority

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

the class SameIds method initData.

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

Example 75 with Priority

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

the class BasicSecondary method initData.

@Test
@Priority(10)
public void initData() {
    SecondaryTestEntity ste = new SecondaryTestEntity("a", "1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(ste);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ste = em.find(SecondaryTestEntity.class, ste.getId());
    ste.setS1("b");
    ste.setS2("2");
    em.getTransaction().commit();
    //
    id = ste.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) 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