Search in sources :

Example 1 with MulIdTestEntity

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

the class SimpleQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    StrIntTestEntity site2 = new StrIntTestEntity("a", 10);
    StrIntTestEntity site3 = new StrIntTestEntity("b", 5);
    em.persist(site1);
    em.persist(site2);
    em.persist(site3);
    id1 = site1.getId();
    id2 = site2.getId();
    id3 = site3.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    mulId1 = new MulId(1, 2);
    em.persist(new MulIdTestEntity(mulId1.getId1(), mulId1.getId2(), "data"));
    embId1 = new EmbId(3, 4);
    em.persist(new EmbIdTestEntity(embId1, "something"));
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setStr1("aBc");
    site2.setNumber(20);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    site3 = em.find(StrIntTestEntity.class, id3);
    site3.setStr1("a");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    em.remove(site1);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) EmbId(org.hibernate.envers.test.entities.ids.EmbId) MulId(org.hibernate.envers.test.entities.ids.MulId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with MulIdTestEntity

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

the class CompositeIds method testHistoryOfId4.

@Test
public void testHistoryOfId4() {
    MulIdTestEntity ver1 = new MulIdTestEntity(id4.getId1(), id4.getId2(), "b");
    MulIdTestEntity ver2 = new MulIdTestEntity(id4.getId1(), id4.getId2(), "b2");
    assert getAuditReader().find(MulIdTestEntity.class, id4, 1) == null;
    assert getAuditReader().find(MulIdTestEntity.class, id4, 2).equals(ver1);
    assert getAuditReader().find(MulIdTestEntity.class, id4, 3).equals(ver2);
    assert getAuditReader().find(MulIdTestEntity.class, id4, 4).equals(ver2);
    assert getAuditReader().find(MulIdTestEntity.class, id4, 5).equals(ver2);
}
Also used : MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) Test(org.junit.Test)

Example 3 with MulIdTestEntity

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

the class CompositeIds method testHistoryOfId3.

@Test
public void testHistoryOfId3() {
    MulIdTestEntity ver1 = new MulIdTestEntity(id3.getId1(), id3.getId2(), "a");
    MulIdTestEntity ver2 = new MulIdTestEntity(id3.getId1(), id3.getId2(), "a2");
    assert getAuditReader().find(MulIdTestEntity.class, id3, 1).equals(ver1);
    assert getAuditReader().find(MulIdTestEntity.class, id3, 2).equals(ver1);
    assert getAuditReader().find(MulIdTestEntity.class, id3, 3).equals(ver2);
    assert getAuditReader().find(MulIdTestEntity.class, id3, 4) == null;
    assert getAuditReader().find(MulIdTestEntity.class, id3, 5) == null;
}
Also used : MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) Test(org.junit.Test)

Example 4 with MulIdTestEntity

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

the class CompositeIds method initData.

@Test
@Priority(10)
public void initData() {
    id1 = new EmbId(1, 2);
    id2 = new EmbId(10, 20);
    id3 = new MulId(100, 101);
    id4 = new MulId(102, 103);
    id5 = new EmbIdWithCustomType(25, CustomEnum.NO);
    id6 = new EmbIdWithCustomType(27, CustomEnum.YES);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(new EmbIdTestEntity(id1, "x"));
    em.persist(new MulIdTestEntity(id3.getId1(), id3.getId2(), "a"));
    em.persist(new EmbIdWithCustomTypeTestEntity(id5, "c"));
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    em.persist(new EmbIdTestEntity(id2, "y"));
    em.persist(new MulIdTestEntity(id4.getId1(), id4.getId2(), "b"));
    em.persist(new EmbIdWithCustomTypeTestEntity(id6, "d"));
    em.getTransaction().commit();
    // Revision 3
    em = getEntityManager();
    em.getTransaction().begin();
    EmbIdTestEntity ete1 = em.find(EmbIdTestEntity.class, id1);
    EmbIdTestEntity ete2 = em.find(EmbIdTestEntity.class, id2);
    MulIdTestEntity mte3 = em.find(MulIdTestEntity.class, id3);
    MulIdTestEntity mte4 = em.find(MulIdTestEntity.class, id4);
    EmbIdWithCustomTypeTestEntity cte5 = em.find(EmbIdWithCustomTypeTestEntity.class, id5);
    EmbIdWithCustomTypeTestEntity cte6 = em.find(EmbIdWithCustomTypeTestEntity.class, id6);
    ete1.setStr1("x2");
    ete2.setStr1("y2");
    mte3.setStr1("a2");
    mte4.setStr1("b2");
    cte5.setStr1("c2");
    cte6.setStr1("d2");
    em.getTransaction().commit();
    // Revision 4
    em = getEntityManager();
    em.getTransaction().begin();
    ete1 = em.find(EmbIdTestEntity.class, id1);
    ete2 = em.find(EmbIdTestEntity.class, id2);
    mte3 = em.find(MulIdTestEntity.class, id3);
    cte5 = em.find(EmbIdWithCustomTypeTestEntity.class, id5);
    cte6 = em.find(EmbIdWithCustomTypeTestEntity.class, id6);
    em.remove(ete1);
    em.remove(mte3);
    em.remove(cte6);
    ete2.setStr1("y3");
    cte5.setStr1("c3");
    em.getTransaction().commit();
    // Revision 5
    em = getEntityManager();
    em.getTransaction().begin();
    ete2 = em.find(EmbIdTestEntity.class, id2);
    em.remove(ete2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) EmbIdWithCustomType(org.hibernate.envers.test.entities.ids.EmbIdWithCustomType) EmbId(org.hibernate.envers.test.entities.ids.EmbId) MulId(org.hibernate.envers.test.entities.ids.MulId) EmbIdWithCustomTypeTestEntity(org.hibernate.envers.test.entities.ids.EmbIdWithCustomTypeTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with MulIdTestEntity

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

the class SimpleQuery method testMultipleIdPropertyRestriction.

@Test
@TestForIssue(jiraKey = "HHH-8567")
public void testMultipleIdPropertyRestriction() {
    MulIdTestEntity ver2 = (MulIdTestEntity) getAuditReader().createQuery().forEntitiesAtRevision(MulIdTestEntity.class, 2).add(AuditEntity.property("id1").eq(mulId1.getId1())).add(AuditEntity.property("id2").eq(mulId1.getId2())).getSingleResult();
    Assert.assertEquals(new MulIdTestEntity(mulId1.getId1(), mulId1.getId2(), "data"), ver2);
}
Also used : MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

MulIdTestEntity (org.hibernate.envers.test.entities.ids.MulIdTestEntity)7 Test (org.junit.Test)7 EntityManager (javax.persistence.EntityManager)3 Priority (org.hibernate.envers.test.Priority)3 MulId (org.hibernate.envers.test.entities.ids.MulId)3 EmbId (org.hibernate.envers.test.entities.ids.EmbId)2 EmbIdTestEntity (org.hibernate.envers.test.entities.ids.EmbIdTestEntity)2 SetRefCollEntityMulId (org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId)2 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)1 EmbIdWithCustomType (org.hibernate.envers.test.entities.ids.EmbIdWithCustomType)1 EmbIdWithCustomTypeTestEntity (org.hibernate.envers.test.entities.ids.EmbIdWithCustomTypeTestEntity)1 TestForIssue (org.hibernate.testing.TestForIssue)1