Here is my situation - the code I have to refactor uses an ALL and DELETE_ORPHAN casade to delete the children of the parent. However, this has been identified as not always desirable, as the child may be owned by another parent. It is intended that the child should only be deleted if no parents exist for it.
I'm relatively new to Hibernate, and have been unable to find any simple solutions in the documentation. Ideally, DELETE_ORPHAN would only delete children that are truely orphans, not just those disassociated from the new deletion. If there was no Hibernate layer, my first instinct would be to query the database for any references for the child, and if none exist, delete it. Perhaps the solution is through HQL? However, since there are nearly 200 cases of this in the code, a quicker solution would be preferred ;)
Thanks in advance
|