If you map a colleciton with inverse="false" cascade="delete", then removing an object from a collection will also delete it. After you refresh() all other objects that have collections referring to the deleted object, your in-memory state will be the same as the DB state. This will achieve what you describe. In the case where you use the DAO to delete the object, in-memory collections referring to the object don't know that it has been deleted, so you still have to refresh() them to sync them up with the DB.
The reason that this is not done by default is that most of the time, if an object can exist on its own or in multiple collections, then removing it from one collection should not remove it from the database or from any other collections. I know that I don't want that behaviour. If a student is in multiple classes, why would he leave school (removed from all classes and deleted from school database) just because he drops out of one class? Not only do I find it counter-intuitive, hibernate already lets me achieve this by delete()ing the object and refresh()ing any objects that refer to it.
_________________ Code tags are your friend. Know them and use them.
|