use of org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity in project hibernate-orm by hibernate.
the class DetachedTest method testUpdatingDetachedEntityWithRelation.
@Test
@Priority(10)
@TestForIssue(jiraKey = "HHH-7543")
public void testUpdatingDetachedEntityWithRelation() {
Session session = getSession();
// Revision 1
session.getTransaction().begin();
ListRefCollEntity parent = new ListRefCollEntity(1, "initial data");
StrTestEntity child = new StrTestEntity("data");
session.save(child);
parent.setCollection(Arrays.asList(child));
session.save(parent);
session.getTransaction().commit();
session.close();
session = getSession();
// Revision 2 - updating detached entity
session.getTransaction().begin();
parent.setData("modified data");
session.update(parent);
session.getTransaction().commit();
session.close();
parentId = parent.getId();
childId = child.getId();
}
use of org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity in project hibernate-orm by hibernate.
the class DetachedTest method testHistoryOfParent.
@Test
public void testHistoryOfParent() {
ListRefCollEntity parent = new ListRefCollEntity(parentId, "initial data");
parent.setCollection(Arrays.asList(new StrTestEntity("data", childId)));
ListRefCollEntity ver1 = getAuditReader().find(ListRefCollEntity.class, parentId, 1);
Assert.assertEquals(parent, ver1);
Assert.assertEquals(parent.getCollection(), ver1.getCollection());
parent.setData("modified data");
ListRefCollEntity ver2 = getAuditReader().find(ListRefCollEntity.class, parentId, 2);
Assert.assertEquals(parent, ver2);
Assert.assertEquals(parent.getCollection(), ver2.getCollection());
}
use of org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity in project hibernate-orm by hibernate.
the class BasicDetachedList method testHistoryOfColl1.
@Test
public void testHistoryOfColl1() {
StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
ListRefCollEntity rev1 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 1);
ListRefCollEntity rev2 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 2);
ListRefCollEntity rev3 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 3);
ListRefCollEntity rev4 = getAuditReader().find(ListRefCollEntity.class, coll1_id, 4);
assert TestTools.checkCollection(rev1.getCollection(), str1);
assert TestTools.checkCollection(rev2.getCollection(), str1, str2);
assert TestTools.checkCollection(rev3.getCollection(), str2);
assert TestTools.checkCollection(rev4.getCollection());
assert "coll1".equals(rev1.getData());
assert "coll1".equals(rev2.getData());
assert "coll1".equals(rev3.getData());
assert "coll1".equals(rev4.getData());
}
use of org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity in project hibernate-orm by hibernate.
the class BasicDetachedList method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
StrTestEntity str1 = new StrTestEntity("str1");
StrTestEntity str2 = new StrTestEntity("str2");
ListRefCollEntity coll1 = new ListRefCollEntity(3, "coll1");
// Revision 1
em.getTransaction().begin();
em.persist(str1);
em.persist(str2);
coll1.setCollection(new ArrayList<StrTestEntity>());
coll1.getCollection().add(str1);
em.persist(coll1);
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
str2 = em.find(StrTestEntity.class, str2.getId());
coll1 = em.find(ListRefCollEntity.class, coll1.getId());
coll1.getCollection().add(str2);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
str1 = em.find(StrTestEntity.class, str1.getId());
coll1 = em.find(ListRefCollEntity.class, coll1.getId());
coll1.getCollection().remove(str1);
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
coll1 = em.find(ListRefCollEntity.class, coll1.getId());
coll1.getCollection().clear();
em.getTransaction().commit();
//
str1_id = str1.getId();
str2_id = str2.getId();
coll1_id = coll1.getId();
}
Aggregations