I use Hibernate, and several times I had to perform a cascading DELETE operation from the parent to its children. I used the following two options.
One option is to set getChildren () on the parent, add the child to the returned collection of children, and let Hibernate automatically cascade DELETE. The disadvantage of this option is that the getChildren () collection should be open, although it is used only to support Hibernate cascading.
Another option is to manually search for and delete children in ParentDao.delete (parent). The disadvantage of this option is the more customizable code. However, this option may work better if it uses batch deletion operators.
Which approach do you mainly use? Do you see other pros and cons?
source
share