Search in sources :

Example 1 with WithModifiedFlagReferencingEntity

use of org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity in project hibernate-orm by hibernate.

the class HasChangedForDefaultNotUsing method initData.

@Test
@Priority(10)
public void initData() {
    PartialModifiedFlagsEntity entity = new PartialModifiedFlagsEntity(entityId);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(entity);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    entity.setData("data1");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    entity.setComp1(new Component1("str1", "str2"));
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    entity.setComp2(new Component2("str1", "str2"));
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    WithModifiedFlagReferencingEntity withModifiedFlagReferencingEntity = new WithModifiedFlagReferencingEntity(refEntityId, "first");
    withModifiedFlagReferencingEntity.setReference(entity);
    em.persist(withModifiedFlagReferencingEntity);
    em.getTransaction().commit();
    // Revision 6
    em.getTransaction().begin();
    withModifiedFlagReferencingEntity = em.find(WithModifiedFlagReferencingEntity.class, refEntityId);
    withModifiedFlagReferencingEntity.setReference(null);
    withModifiedFlagReferencingEntity.setSecondReference(entity);
    em.merge(withModifiedFlagReferencingEntity);
    em.getTransaction().commit();
    // Revision 7
    em.getTransaction().begin();
    entity.getStringSet().add("firstElement");
    entity.getStringSet().add("secondElement");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 8
    em.getTransaction().begin();
    entity.getStringSet().remove("secondElement");
    entity.getStringMap().put("someKey", "someValue");
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 9 - main entity doesn't change
    em.getTransaction().begin();
    StrTestEntity strTestEntity = new StrTestEntity("first");
    em.persist(strTestEntity);
    em.getTransaction().commit();
    // Revision 10
    em.getTransaction().begin();
    entity.getEntitiesSet().add(strTestEntity);
    entity = em.merge(entity);
    em.getTransaction().commit();
    // Revision 11
    em.getTransaction().begin();
    entity.getEntitiesSet().remove(strTestEntity);
    entity.getEntitiesMap().put("someKey", strTestEntity);
    em.merge(entity);
    em.getTransaction().commit();
    // Revision 12 - main entity doesn't change
    em.getTransaction().begin();
    strTestEntity.setStr("second");
    em.merge(strTestEntity);
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Component2(org.hibernate.envers.test.entities.components.Component2) WithModifiedFlagReferencingEntity(org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity) PartialModifiedFlagsEntity(org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Priority (org.hibernate.envers.test.Priority)1 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)1 Component1 (org.hibernate.envers.test.entities.components.Component1)1 Component2 (org.hibernate.envers.test.entities.components.Component2)1 PartialModifiedFlagsEntity (org.hibernate.envers.test.integration.modifiedflags.entities.PartialModifiedFlagsEntity)1 WithModifiedFlagReferencingEntity (org.hibernate.envers.test.integration.modifiedflags.entities.WithModifiedFlagReferencingEntity)1 Test (org.junit.Test)1