Search in sources :

Example 6 with StrTestEntity

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

the class DoubleFlushAddMod method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity fe = new StrTestEntity("x");
    em.persist(fe);
    em.flush();
    fe.setStr("y");
    em.flush();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("z");
    em.flush();
    em.getTransaction().commit();
    //
    id = fe.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 7 with StrTestEntity

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

the class DoubleFlushAddMod method testHistoryOfId.

@Test
public void testHistoryOfId() {
    StrTestEntity ver1 = new StrTestEntity("y", id);
    StrTestEntity ver2 = new StrTestEntity("z", id);
    assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
    assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 8 with StrTestEntity

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

the class ManualFlush method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity fe = new StrTestEntity("x");
    em.persist(fe);
    em.flush();
    em.getTransaction().commit();
    // No revision - we change the data, but do not flush the session
    em.getTransaction().begin();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("y");
    em.getTransaction().commit();
    // Revision 2 - only the first change should be saved
    em.getTransaction().begin();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("z");
    em.flush();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("z2");
    em.getTransaction().commit();
    //
    id = fe.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 9 with StrTestEntity

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

Example 10 with StrTestEntity

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

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