Search in sources :

Example 81 with StrTestEntity

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

the class DoubleFlushModMod method testHistoryOfId.

@Test
public void testHistoryOfId() {
    StrTestEntity ver1 = new StrTestEntity("x", 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 82 with StrTestEntity

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

the class ManualFlush method testHistoryOfId.

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

Example 83 with StrTestEntity

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

the class DetachedTest method testUpdatingDetachedEntityWithRelation.

@Test
@Priority(10)
@TestForIssue(jiraKey = "HHH-7543")
public void testUpdatingDetachedEntityWithRelation() {
    Session session = getSession();
    // Revision 1
    session.getTransaction().begin();
    ListRefCollEntity parent = new ListRefCollEntity(1, "initial data");
    StrTestEntity child = new StrTestEntity("data");
    session.save(child);
    parent.setCollection(Arrays.asList(child));
    session.save(parent);
    session.getTransaction().commit();
    session.close();
    session = getSession();
    // Revision 2 - updating detached entity
    session.getTransaction().begin();
    parent.setData("modified data");
    session.update(parent);
    session.getTransaction().commit();
    session.close();
    parentId = parent.getId();
    childId = child.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) ListRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity) Session(org.hibernate.Session) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority) TestForIssue(org.hibernate.testing.TestForIssue)

Example 84 with StrTestEntity

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

the class DetachedTest method testHistoryOfParent.

@Test
public void testHistoryOfParent() {
    ListRefCollEntity parent = new ListRefCollEntity(parentId, "initial data");
    parent.setCollection(Arrays.asList(new StrTestEntity("data", childId)));
    ListRefCollEntity ver1 = getAuditReader().find(ListRefCollEntity.class, parentId, 1);
    Assert.assertEquals(parent, ver1);
    Assert.assertEquals(parent.getCollection(), ver1.getCollection());
    parent.setData("modified data");
    ListRefCollEntity ver2 = getAuditReader().find(ListRefCollEntity.class, parentId, 2);
    Assert.assertEquals(parent, ver2);
    Assert.assertEquals(parent.getCollection(), ver2.getCollection());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) ListRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity) Test(org.junit.Test)

Example 85 with StrTestEntity

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

the class QueryingWithProxyObjectTest method testQueryingWithProxyObject.

@Test
@TestForIssue(jiraKey = "HHH-4760")
@SuppressWarnings("unchecked")
public void testQueryingWithProxyObject() {
    StrTestEntity originalSte = new StrTestEntity("data", id);
    // Load the proxy instance
    StrTestEntity proxySte = (StrTestEntity) getSession().load(StrTestEntity.class, id);
    Assert.assertTrue(getAuditReader().isEntityClassAudited(proxySte.getClass()));
    StrTestEntity ste = getAuditReader().find(proxySte.getClass(), proxySte.getId(), 1);
    Assert.assertEquals(originalSte, ste);
    List<Number> revisions = getAuditReader().getRevisions(proxySte.getClass(), proxySte.getId());
    Assert.assertEquals(Arrays.asList(1), revisions);
    List<StrTestEntity> entities = getAuditReader().createQuery().forEntitiesAtRevision(proxySte.getClass(), 1).getResultList();
    Assert.assertEquals(Arrays.asList(originalSte), entities);
    ste = (StrTestEntity) getAuditReader().createQuery().forRevisionsOfEntity(proxySte.getClass(), true, false).getSingleResult();
    Assert.assertEquals(originalSte, ste);
    ste = (StrTestEntity) getAuditReader().createQuery().forEntitiesModifiedAtRevision(proxySte.getClass(), 1).getSingleResult();
    Assert.assertEquals(originalSte, ste);
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)103 Test (org.junit.Test)99 EntityManager (javax.persistence.EntityManager)51 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)5 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)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