Search in sources :

Example 41 with Priority

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

the class JoinColumnNaturalIdTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getOrCreateEntityManager();
    try {
        // Revision 1
        em.getTransaction().begin();
        Customer customer = new Customer();
        customer.setCustomerNumber("1234567");
        customer.setName("ACME");
        em.persist(customer);
        em.getTransaction().commit();
        customerId = customer.getId();
        // Revision 2
        em.getTransaction().begin();
        Device device = new Device();
        device.setCustomer(customer);
        Account account = new Account();
        account.setCustomer(customer);
        em.persist(account);
        em.persist(device);
        em.getTransaction().commit();
        accountId = account.getId();
        deviceId = device.getId();
        // Revision 3
        em.getTransaction().begin();
        em.remove(account);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 42 with Priority

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

the class NotInsertable method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    NotInsertableTestEntity dte = new NotInsertableTestEntity("data1");
    em.persist(dte);
    id1 = dte.getId();
    em.getTransaction().commit();
    em.getTransaction().begin();
    dte = em.find(NotInsertableTestEntity.class, id1);
    dte.setData("data2");
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 43 with Priority

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

the class ManyToOneNotInsertable method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    mto_id1 = 1;
    type_id1 = 2;
    type_id2 = 3;
    // Rev 1
    // Preparing the types
    em.getTransaction().begin();
    NotInsertableEntityType type1 = new NotInsertableEntityType(type_id1, "type1");
    NotInsertableEntityType type2 = new NotInsertableEntityType(type_id2, "type2");
    em.persist(type1);
    em.persist(type2);
    em.getTransaction().commit();
    // Rev 2
    em.getTransaction().begin();
    ManyToOneNotInsertableEntity master = new ManyToOneNotInsertableEntity(mto_id1, type_id1, type1);
    em.persist(master);
    em.getTransaction().commit();
    // Rev 2
    em.getTransaction().begin();
    master = em.find(ManyToOneNotInsertableEntity.class, mto_id1);
    master.setNumber(type_id2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 44 with Priority

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

the class PropertyNotUpdatableTest method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    PropertyNotUpdatableEntity entity = new PropertyNotUpdatableEntity("data", "constant data 1", "constant data 2");
    em.persist(entity);
    em.getTransaction().commit();
    id = entity.getId();
    // Revision 2
    em.getTransaction().begin();
    entity = em.find(PropertyNotUpdatableEntity.class, entity.getId());
    entity.setData("modified data");
    entity.setConstantData1(null);
    em.merge(entity);
    em.getTransaction().commit();
    em.close();
    // Re-opening entity manager to re-initialize non-updatable fields
    em = getEntityManager();
    // with database values. Otherwise PostUpdateEvent#getOldState() returns previous
    // memory state. This can be achieved using EntityManager#refresh(Object) method as well.
    // Revision 3
    em.getTransaction().begin();
    entity = em.find(PropertyNotUpdatableEntity.class, entity.getId());
    entity.setData("another modified data");
    entity.setConstantData2("invalid data");
    em.merge(entity);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    em.refresh(entity);
    em.remove(entity);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 45 with Priority

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

the class BidirectionalManyToOneOptionalTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager entityManager = getEntityManager();
    try {
        // Revision 1
        entityManager.getTransaction().begin();
        // store refing with null refed entity
        BiRefingOptionalEntity refingWithNoRefed = new BiRefingOptionalEntity();
        refingWithNoRefed.setReference(null);
        entityManager.persist(refingWithNoRefed);
        // store refing with non-null refed entity
        BiRefingOptionalEntity refing = new BiRefingOptionalEntity();
        BiRefedOptionalEntity refed = new BiRefedOptionalEntity();
        refed.getReferences().add(refing);
        refing.setReference(refed);
        entityManager.persist(refing);
        entityManager.persist(refed);
        entityManager.getTransaction().commit();
        this.refingId = refing.getId();
        this.refedId = refed.getId();
        this.refingWithNoRefedId = refingWithNoRefed.getId();
    } finally {
        entityManager.close();
    }
}
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