use of org.hibernate.test.event.collection.ChildEntity in project hibernate-orm by hibernate.
the class AbstractAssociationCollectionEventTest method testDeleteParentButNotChild.
@Test
public void testDeleteParentButNotChild() {
CollectionListeners listeners = new CollectionListeners(sessionFactory());
ParentWithCollection parent = createParentWithOneChild("parent", "child");
ChildEntity child = (ChildEntity) parent.getChildren().iterator().next();
listeners.clear();
Session s = openSession();
Transaction tx = s.beginTransaction();
parent = (ParentWithCollection) s.get(parent.getClass(), parent.getId());
child = (ChildEntity) s.get(child.getClass(), child.getId());
parent.removeChild(child);
s.delete(parent);
tx.commit();
s.close();
int index = 0;
checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
if (child instanceof ChildWithBidirectionalManyToMany) {
checkResult(listeners, listeners.getInitializeCollectionListener(), (ChildWithBidirectionalManyToMany) child, index++);
}
checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, index++);
checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, index++);
if (child instanceof ChildWithBidirectionalManyToMany) {
checkResult(listeners, listeners.getPreCollectionUpdateListener(), (ChildWithBidirectionalManyToMany) child, index++);
checkResult(listeners, listeners.getPostCollectionUpdateListener(), (ChildWithBidirectionalManyToMany) child, index++);
}
checkNumberOfResults(listeners, index);
}
Aggregations