Search in sources :

Example 1 with EmbIdTestEntity

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

the class SimpleQuery method testEmbeddedIdPropertyRestriction.

@Test
@TestForIssue(jiraKey = "HHH-8567")
public void testEmbeddedIdPropertyRestriction() {
    EmbIdTestEntity ver2 = (EmbIdTestEntity) getAuditReader().createQuery().forEntitiesAtRevision(EmbIdTestEntity.class, 2).add(AuditEntity.property("id.x").eq(embId1.getX())).add(AuditEntity.property("id.y").eq(embId1.getY())).getSingleResult();
    Assert.assertEquals(new EmbIdTestEntity(embId1, "something"), ver2);
}
Also used : EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with EmbIdTestEntity

use of org.hibernate.envers.test.entities.ids.EmbIdTestEntity 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 3 with EmbIdTestEntity

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

the class BasicDetachedSetWithEmbId method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    str1_id = new EmbId(1, 2);
    str2_id = new EmbId(3, 4);
    coll1_id = new EmbId(5, 6);
    EmbIdTestEntity str1 = new EmbIdTestEntity(str1_id, "str1");
    EmbIdTestEntity str2 = new EmbIdTestEntity(str2_id, "str2");
    SetRefCollEntityEmbId coll1 = new SetRefCollEntityEmbId(coll1_id, "coll1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    coll1.setCollection(new HashSet<EmbIdTestEntity>());
    coll1.getCollection().add(str1);
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    str2 = em.find(EmbIdTestEntity.class, str2.getId());
    coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
    coll1.getCollection().add(str2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    str1 = em.find(EmbIdTestEntity.class, str1.getId());
    coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
    coll1.getCollection().remove(str1);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    coll1 = em.find(SetRefCollEntityEmbId.class, coll1.getId());
    coll1.getCollection().clear();
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) SetRefCollEntityEmbId(org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityEmbId) EmbId(org.hibernate.envers.test.entities.ids.EmbId) SetRefCollEntityEmbId(org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityEmbId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 4 with EmbIdTestEntity

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

the class UnidirectionalMulIdWithNulls method initData.

@Test
@Priority(10)
public void initData() {
    ei = new EmbId(1, 2);
    EntityManager em = getEntityManager();
    // Revision 1
    EmbIdTestEntity eite = new EmbIdTestEntity(ei, "data");
    UniRefIngMulIdEntity notNullRef = new UniRefIngMulIdEntity(1, "data 1", eite);
    UniRefIngMulIdEntity nullRef = new UniRefIngMulIdEntity(2, "data 2", null);
    em.getTransaction().begin();
    em.persist(eite);
    em.persist(notNullRef);
    em.persist(nullRef);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) EmbId(org.hibernate.envers.test.entities.ids.EmbId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with EmbIdTestEntity

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

the class CompositeIds method testHistoryOfId2.

@Test
public void testHistoryOfId2() {
    EmbIdTestEntity ver1 = new EmbIdTestEntity(id2, "y");
    EmbIdTestEntity ver2 = new EmbIdTestEntity(id2, "y2");
    EmbIdTestEntity ver3 = new EmbIdTestEntity(id2, "y3");
    assert getAuditReader().find(EmbIdTestEntity.class, id2, 1) == null;
    assert getAuditReader().find(EmbIdTestEntity.class, id2, 2).equals(ver1);
    assert getAuditReader().find(EmbIdTestEntity.class, id2, 3).equals(ver2);
    assert getAuditReader().find(EmbIdTestEntity.class, id2, 4).equals(ver3);
    assert getAuditReader().find(EmbIdTestEntity.class, id2, 5) == null;
}
Also used : EmbIdTestEntity(org.hibernate.envers.test.entities.ids.EmbIdTestEntity) Test(org.junit.Test)

Aggregations

EmbIdTestEntity (org.hibernate.envers.test.entities.ids.EmbIdTestEntity)9 Test (org.junit.Test)9 EntityManager (javax.persistence.EntityManager)4 Priority (org.hibernate.envers.test.Priority)4 EmbId (org.hibernate.envers.test.entities.ids.EmbId)4 MulId (org.hibernate.envers.test.entities.ids.MulId)2 MulIdTestEntity (org.hibernate.envers.test.entities.ids.MulIdTestEntity)2 SetRefCollEntityEmbId (org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityEmbId)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