use of org.hibernate.envers.test.entities.manytomany.SetOwningEntity in project hibernate-orm by hibernate.
the class ValidityAuditStrategyManyToManyTest method testHistoryOfIng1.
@Test
public void testHistoryOfIng1() {
SetOwningEntity ver_empty = createOwningEntity();
SetOwningEntity ver_child = createOwningEntity(new SetOwnedEntity(ed_id, "child"));
assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 1), ver_empty);
assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 2), ver_child);
assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 3), ver_empty);
assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 4), ver_child);
assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 5), ver_empty);
}
use of org.hibernate.envers.test.entities.manytomany.SetOwningEntity in project hibernate-orm by hibernate.
the class ValidityAuditStrategyManyToManyTest method createOwningEntity.
private SetOwningEntity createOwningEntity(SetOwnedEntity... owned) {
SetOwningEntity result = new SetOwningEntity(ing_id, "parent");
result.setReferences(new HashSet<SetOwnedEntity>());
for (SetOwnedEntity setOwnedEntity : owned) {
result.getReferences().add(setOwnedEntity);
}
return result;
}
use of org.hibernate.envers.test.entities.manytomany.SetOwningEntity in project hibernate-orm by hibernate.
the class RemovedObjectQueryTest method testOwningManyToManySameRevision.
@Test
public void testOwningManyToManySameRevision() {
List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetOwnedEntity.class, false, true).add(AuditEntity.id().eq(6)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
Object[] objArray = (Object[]) queryResult.get(0);
Assert.assertEquals(7, getRevisionNumber(objArray[1]));
SetOwnedEntity setOwnedEntity = (SetOwnedEntity) objArray[0];
Assert.assertEquals("Example Data 1", setOwnedEntity.getData());
Hibernate.initialize(setOwnedEntity.getReferencing());
Assert.assertEquals(TestTools.makeSet(new SetOwningEntity(5, "Demo Data 1")), setOwnedEntity.getReferencing());
}
use of org.hibernate.envers.test.entities.manytomany.SetOwningEntity in project hibernate-orm by hibernate.
the class BasicSet method testHistoryOfEdIng1.
@Test
public void testHistoryOfEdIng1() {
SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id);
SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id);
SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing1_id, 1);
SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing1_id, 2);
SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing1_id, 3);
SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing1_id, 4);
SetOwningEntity rev5 = getAuditReader().find(SetOwningEntity.class, ing1_id, 5);
assert rev1.getReferences().equals(Collections.EMPTY_SET);
assert rev2.getReferences().equals(TestTools.makeSet(ed1));
assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2));
assert rev4.getReferences().equals(TestTools.makeSet(ed2));
assert rev5.getReferences().equals(Collections.EMPTY_SET);
}
use of org.hibernate.envers.test.entities.manytomany.SetOwningEntity in project hibernate-orm by hibernate.
the class BasicSet method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
SetOwnedEntity ed1 = new SetOwnedEntity(1, "data_ed_1");
SetOwnedEntity ed2 = new SetOwnedEntity(2, "data_ed_2");
SetOwningEntity ing1 = new SetOwningEntity(3, "data_ing_1");
SetOwningEntity ing2 = new SetOwningEntity(4, "data_ing_2");
// Revision 1
em.getTransaction().begin();
em.persist(ed1);
em.persist(ed2);
em.persist(ing1);
em.persist(ing2);
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ing2 = em.find(SetOwningEntity.class, ing2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ing1.setReferences(new HashSet<SetOwnedEntity>());
ing1.getReferences().add(ed1);
ing2.setReferences(new HashSet<SetOwnedEntity>());
ing2.getReferences().add(ed1);
ing2.getReferences().add(ed2);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ing1.getReferences().add(ed2);
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ed2 = em.find(SetOwnedEntity.class, ed2.getId());
ed1 = em.find(SetOwnedEntity.class, ed1.getId());
ing1.getReferences().remove(ed1);
em.getTransaction().commit();
// Revision 5
em.getTransaction().begin();
ing1 = em.find(SetOwningEntity.class, ing1.getId());
ing1.setReferences(null);
em.getTransaction().commit();
//
ed1_id = ed1.getId();
ed2_id = ed2.getId();
ing1_id = ing1.getId();
ing2_id = ing2.getId();
}
Aggregations