Search in sources :

Example 16 with StrTestEntity

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

the class VersionsJoinTableNaming method initData.

@Test
@Priority(10)
public void initData() {
    VersionsJoinTableTestEntity uni1 = new VersionsJoinTableTestEntity(1, "data1");
    StrTestEntity str1 = new StrTestEntity("str1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    uni1.setCollection(new HashSet<StrTestEntity>());
    em.persist(uni1);
    em.persist(str1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    uni1 = em.find(VersionsJoinTableTestEntity.class, uni1.getId());
    str1 = em.find(StrTestEntity.class, str1.getId());
    uni1.getCollection().add(str1);
    em.getTransaction().commit();
    //
    uni1_id = uni1.getId();
    str1_id = str1.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 17 with StrTestEntity

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

the class HasChangedOneToManyInComponent method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity ste1 = new StrTestEntity();
    ste1.setStr("str1");
    StrTestEntity ste2 = new StrTestEntity();
    ste2.setStr("str2");
    em.persist(ste1);
    em.persist(ste2);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity(new OneToManyComponent("data1"));
    otmcte1.getComp1().getEntities().add(ste1);
    em.persist(otmcte1);
    em.getTransaction().commit();
    // Revision 3
    em = getEntityManager();
    em.getTransaction().begin();
    otmcte1 = em.find(OneToManyComponentTestEntity.class, otmcte1.getId());
    otmcte1.getComp1().getEntities().add(ste2);
    em.getTransaction().commit();
    otmcte_id1 = otmcte1.getId();
}
Also used : OneToManyComponent(org.hibernate.envers.test.entities.components.relations.OneToManyComponent) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) OneToManyComponentTestEntity(org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 18 with StrTestEntity

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

the class DefaultTrackingEntitiesTest method testTrackAddedEntities.

@Test
public void testTrackAddedEntities() {
    StrTestEntity ste = new StrTestEntity("x", steId);
    StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId);
    assert TestTools.checkCollection(getCrossTypeRevisionChangesReader().findEntities(1), ste, site);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 19 with StrTestEntity

use of org.hibernate.envers.test.entities.StrTestEntity 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 20 with StrTestEntity

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

the class TrackingEntitiesMultipleChangesTest method testTrackUpdateAndRemoveTheSameEntity.

@Test
public void testTrackUpdateAndRemoveTheSameEntity() {
    StrTestEntity ste1 = new StrTestEntity(null, steId1);
    Assert.assertEquals(TestTools.makeSet(ste1), new HashSet<Object>(getCrossTypeRevisionChangesReader().findEntities(3)));
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) 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