I am new to Hibernate and want to use it in a Swing application. My problem is that I don't know how to deal with changes made by other users properly.
For example, consider a parent-child relationship and that another user has added (or deleted) a child since I loaded the objects from the database. If I now try to delete the parent object, Hibernate will delete its child objects first, but since the database has changed, my transaction will fail with a ConstraintViolationException (or StaleStateException).
One solution I can think of is to make the database responsible for handling the deletion of children, by using on-delete="cascade".
However, if parent and children belong to the same table (a tree), I cannot use this technique, because our database, MSSQL 2000, does not support cascading deletes on self-referencing tables.
Are there any alternatives? Should I tell a parent to update its view of its children before deleting it? How would I do that?
|