use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.
the class BasicSet method testHistoryOfEdId2.
@Test
public void testHistoryOfEdId2() {
SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id);
SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id);
SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 1);
SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 2);
SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 3);
SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 4);
SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed2_id, 5);
assert rev1.getReferencing().equals(Collections.EMPTY_SET);
assert rev2.getReferencing().equals(TestTools.makeSet(ing2));
assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2));
assert rev4.getReferencing().equals(TestTools.makeSet(ing1, ing2));
assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
}
use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.
the class BasicSet method testHistoryOfEdId1.
@Test
public void testHistoryOfEdId1() {
SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id);
SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id);
SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 1);
SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 2);
SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 3);
SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 4);
SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 5);
assert rev1.getReferencing().equals(Collections.EMPTY_SET);
assert rev2.getReferencing().equals(TestTools.makeSet(ing1, ing2));
assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2));
assert rev4.getReferencing().equals(TestTools.makeSet(ing2));
assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
}
use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.
the class BasicSet method testHistoryOfEdIng2.
@Test
public void testHistoryOfEdIng2() {
SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id);
SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id);
SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing2_id, 1);
SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing2_id, 2);
SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing2_id, 3);
SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing2_id, 4);
SetOwningEntity rev5 = getAuditReader().find(SetOwningEntity.class, ing2_id, 5);
assert rev1.getReferences().equals(Collections.EMPTY_SET);
assert rev2.getReferences().equals(TestTools.makeSet(ed1, ed2));
assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2));
assert rev4.getReferences().equals(TestTools.makeSet(ed1, ed2));
assert rev5.getReferences().equals(TestTools.makeSet(ed1, ed2));
}
use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.
the class ValidityAuditStrategyManyToManyTest method testMultipleAddAndRemove.
@Test
@Priority(5)
public void testMultipleAddAndRemove() {
final EntityManager em = getEntityManager();
// Revision 2: add child for first time
em.getTransaction().begin();
SetOwningEntity owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
SetOwnedEntity ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
owningEntity.setReferences(new HashSet<SetOwnedEntity>());
owningEntity.getReferences().add(ownedEntity);
em.getTransaction().commit();
em.clear();
// Revision 3: remove child
em.getTransaction().begin();
owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
owningEntity.getReferences().remove(ownedEntity);
em.getTransaction().commit();
em.clear();
// Revision 4: add child again
em.getTransaction().begin();
owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
owningEntity.getReferences().add(ownedEntity);
em.getTransaction().commit();
em.clear();
// Revision 5: remove child again
em.getTransaction().begin();
owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
owningEntity.getReferences().remove(ownedEntity);
em.getTransaction().commit();
em.clear();
// now the set owning entity list should be empty again
owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
assertEquals(owningEntity.getReferences().size(), 0);
}
use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.
the class ValidityAuditStrategyManyToManyTest method initData.
@Test
@Priority(10)
public void initData() {
final EntityManager em = getEntityManager();
final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent");
final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child");
// Revision 1: Initial persist
em.getTransaction().begin();
em.persist(setOwningEntity);
em.persist(setOwnedEntity);
em.getTransaction().commit();
em.clear();
ing_id = setOwningEntity.getId();
ed_id = setOwnedEntity.getId();
}
Aggregations