Could someone explain to me why the following doesn't work (runways is a Hibernate PersistentSet) ?
System.out.println("size before " + runways.size());
Iterator<Runway> deleteIterator = runways.iterator();
while (deleteIterator.hasNext()) {
Runway rwy = deleteIterator.next();
if (rwy == rwy3) {
System.out.println("remove !");
deleteIterator.remove();
}
}
System.out.println("size after " + runways.size());
I get the system.Out logs:
INFO: size before 3
INFO: remove !
INFO: size after 3
I thought that deletion through the iterator was safe and possible. You see the log "remove"! which indicates that the remove() method is called.
EDIT : PersistentSet has problem with the remove method from the Iterator interface.