From: Thom P. (JIRA) <no...@at...> - 2006-03-22 15:23:16
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-785?page=comments#action_22560 ] Thom Pischke commented on HHH-785: ---------------------------------- A pity. I can imagine why this would be very difficult to implement, but it'd be fantastic if Hibernate were someday able to handle moving a child to a new parent without needing to resort to handling deletion of orphans manually. We have many examples in our code where we move a child to a new parent. In our case, we do a lot of modification of detached entities. When the time comes to save all the changes (User hits 'Save' button), then we start a Session/Transaction and 'update' the model object to reattach it to the Session and write all the changes to disk. These updates include both removal (deletion) of objects, and transferral of objects to new parents. Since many such changes can accumulate outside the scope of a Session, manual handling of orphan deletion would be very difficult, since we would essentially need to query the database after writing all the changes to manually find all orphaned objects. Not even sure that would be possible, since we would get exceptions if the parent were ever deleted, since the foreign key constraints of the children would be violated. Our workaround for all this is simply to clone the children which need to be moved to new parents, resulting in the original child being deleted, and a new identical child being persisted, but with a different parent. Of course, this is inelegant, inefficient and results in quite an accumulation of clones, since we also have to store 'undo' information for each movement of the child. Anyway, probably you're sighing and thinking 'What the hell does this guy think he's doing?', but I thought it might be useful to someone if I added our use-case to this issues discussion. > Persistence through cascading should have higher precedence than orphan-delete > ------------------------------------------------------------------------------ > > Key: HHH-785 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-785 > Project: Hibernate3 > Type: Improvement > Components: core > Versions: 3.1 beta 1 > Reporter: Christian Bauer > > > A typical tree mapped using an adjacency list: > <many-to-one name="parent" cascade="none"/> > <set name="children" cascade="all, delete-orphan"/> > A normal tree operation is moving a node: > a.remove(b); > c.add(b); > This results in an exception, as Hibernate currently rates the delete-orphan as more important and warns that the node would become persistent again through cascading. However, this is the only way to implement relocation of a node in a tree without resorting to complex session coding. I argue that the "delete orphans" guarantee given in the mapping should not have precedence over the the actual non-orphaned persistent state in the Session. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |