Cascade = "All-delete-orphan" processing

Source: Internet
Author: User

For example, we now have a parent object and a children's set in the parent object.
The children data is not very important. For convenience, when we modify the parent
1. Delete all children and add all new children.
This morning, when I was doing this, I encountered a problem, that is, when I updated the parent, I reported
Don't dereference a collection with cascade = "all-delete-Orphan"
Usually half an hour of Data Query and debugging, finally found a solution to the problem
At the beginning, my practice was as follows:
Parent = parentservice. findparentbyid (ID );
Parent. getchildren. Clear ();
Parent. setchildren (newchildren );
Parentservice. updateparent (parent );
In this case, an exception of don't dereference a collection with cascade = "all-delete-Orphan" will be reported.
Originally, for the children set of parent, it is a persistent set, which exists in the object pool of hibernate, through
After parent. setchildren (newchildren) is set, the reference of parent to children set has been referred to a set outside the object pool.
The method after querying the information is:
Parent = parentservice. findparentbyid (ID );
Parent. getchildren. Clear ();
Parent. getchildren. addall (newchildren );
Parentservice. updateparent (parent );
After several tests, the problem was solved.
HBM configuration is as follows:
<Set lazy = "true" name = "children" cascade = "All, delete-Orphan" inverse = "true">
<Key column = "parent_id"/>
<One-to-learn class = "child"/>
In addition, Hibernate 3 has modified the options in cascade, And now it does not have the all-delete-orphan option, although hibernate
This option is still supported internally ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.