Search in sources :

Example 1 with Component

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

the class CompositeCustomType method testRemoval.

@Test
@TestForIssue(jiraKey = "HHH-9207")
@FailureExpected(jiraKey = "HHH-9207")
public void testRemoval() {
    EntityManager em = getEntityManager();
    final Component comp1 = new Component(null, 11);
    final Component comp2 = new Component(null, 22);
    final CompositeCustomTypeSetEntity entity = new CompositeCustomTypeSetEntity();
    entity.setComponents(new HashSet<Component>());
    entity.getComponents().add(comp1);
    entity.getComponents().add(comp2);
    em.getTransaction().begin();
    em.persist(entity);
    em.getTransaction().commit();
    em.getTransaction().begin();
    entity.getComponents().remove(comp1);
    em.getTransaction().commit();
    CompositeCustomTypeSetEntity rev1 = getAuditReader().find(CompositeCustomTypeSetEntity.class, entity.getId(), 1);
    CompositeCustomTypeSetEntity rev2 = getAuditReader().find(CompositeCustomTypeSetEntity.class, entity.getId(), 2);
    assertEquals("Unexpected components", TestTools.makeSet(comp1, comp2), rev1.getComponents());
    assertEquals("Unexpected components", TestTools.makeSet(comp2), rev2.getComponents());
}
Also used : CompositeCustomTypeSetEntity(org.hibernate.envers.test.entities.collection.CompositeCustomTypeSetEntity) EntityManager(javax.persistence.EntityManager) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with Component

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

the class CompositeCustom method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
    // Revision 1 (persisting 1 entity)
    em.getTransaction().begin();
    ccte.setComponent(new Component("a", 1));
    em.persist(ccte);
    em.getTransaction().commit();
    // Revision 2 (changing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.getComponent().setProp1("b");
    em.getTransaction().commit();
    // Revision 3 (replacing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.setComponent(new Component("c", 3));
    em.getTransaction().commit();
    //
    ccte_id = ccte.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) CompositeCustomTypeEntity(org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with Component

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

the class HasChangedCompositeCustom method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
    // Revision 1 (persisting 1 entity)
    em.getTransaction().begin();
    ccte.setComponent(new Component("a", 1));
    em.persist(ccte);
    em.getTransaction().commit();
    // Revision 2 (changing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.getComponent().setProp1("b");
    em.getTransaction().commit();
    // Revision 3 (replacing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.setComponent(new Component("c", 3));
    em.getTransaction().commit();
    //
    ccte_id = ccte.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) CompositeCustomTypeEntity(org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 4 with Component

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

the class CompositeCustom method testHistoryOfCcte.

@Test
public void testHistoryOfCcte() {
    CompositeCustomTypeEntity rev1 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 1);
    CompositeCustomTypeEntity rev2 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 2);
    CompositeCustomTypeEntity rev3 = getAuditReader().find(CompositeCustomTypeEntity.class, ccte_id, 3);
    assert rev1.getComponent().equals(new Component("a", 1));
    assert rev2.getComponent().equals(new Component("b", 1));
    assert rev3.getComponent().equals(new Component("c", 3));
}
Also used : CompositeCustomTypeEntity(org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test)

Aggregations

Component (org.hibernate.envers.test.entities.customtype.Component)4 Test (org.junit.Test)4 EntityManager (javax.persistence.EntityManager)3 CompositeCustomTypeEntity (org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity)3 Priority (org.hibernate.envers.test.Priority)2 CompositeCustomTypeSetEntity (org.hibernate.envers.test.entities.collection.CompositeCustomTypeSetEntity)1 FailureExpected (org.hibernate.testing.FailureExpected)1 TestForIssue (org.hibernate.testing.TestForIssue)1