Session session = openSession();
session.beginTransaction();
session.save( parent );
session.flush();
// at this point, the map on parent has now been replaced with a PersistentMap...
PersistentMap children = ( PersistentMap ) parent.getChildren();
Object old = children.put( child.getName(), child );
assertTrue( old == child );
assertFalse( children.isDirty() );
old = children.remove( otherChild.getName() );
assertNull( old );
assertFalse( children.isDirty() );
HashMap otherMap = new HashMap();
otherMap.put( child.getName(), child );
children.putAll( otherMap );
assertFalse( children.isDirty() );
otherMap = new HashMap();
otherMap.put( otherChild.getName(), otherChild );
children.putAll( otherMap );
assertTrue( children.isDirty() );
children.clearDirty();
session.delete( child );
children.clear();
assertTrue( children.isDirty() );
session.flush();
children.clear();
assertFalse( children.isDirty() );
session.delete( parent );
session.getTransaction().commit();
session.close();
}