ListOwner parent = new ListOwner( "root" );
ListOwner child = new ListOwner( "c1" );
parent.getChildren().add( child );
child.setParent( parent );
ListOwner otherChild = new ListOwner( "c2" );
Session session = openSession();
session.beginTransaction();
session.save( parent );
session.flush();
// at this point, the list on parent has now been replaced with a PersistentList...
PersistentList children = ( PersistentList ) parent.getChildren();
assertFalse( children.remove( otherChild ) );
assertFalse( children.isDirty() );
ArrayList otherCollection = new ArrayList();
otherCollection.add( child );
assertFalse( children.retainAll( otherCollection ) );
assertFalse( children.isDirty() );
otherCollection = new ArrayList();
otherCollection.add( otherChild );
assertFalse( children.removeAll( otherCollection ) );
assertFalse( children.isDirty() );
children.clear();
session.delete( child );
assertTrue( children.isDirty() );
session.flush();
children.clear();
assertFalse( children.isDirty() );
session.delete( parent );
session.getTransaction().commit();
session.close();