Hibernate version:3.6.2 final
Personal Oracle Database 11g Release 18.104.22.168.0 - Production
The relationship is like 1 organization can have multiple volunteers. However 1 volunteer may or may not be linked to an organization.
Ok, lets say there is 1 volunteer linked with this organization.
Then if we delink this volunteer from the organization and then call the delete on the organization, shouldn't it just leave an orphan volunteer?
It instead deletes the volunteer as well.
This generates the following SQL:
I think that's incorrect.Could you please suggest?
As far as I know cascade all includes cascade orphan-delete so you might want do remove that.
I know what you want to do and the possible explanation i have might be wrong!
Explanation I have is:
Hibernate is a state machine and it just checks the state of the managed entities when you tell it to. Transaction.commit, session.flush, etc.
If you do all those things in one transaction hibernates just sees.
Before state check:
After/in state check:
Relationship not there! Check if cascade orphan delete is set and remove all orphans.
This is my understanding of hibernate so far. Might be right or totally wrong so please feel free to correct me!
Please correct my English.
Joined: Aug 05, 2008
Manuel, can you point me to some document according to which cascade = all included delete-orphan? AFAIK, it doesn't.
An Organisation is being deleted and when this operation is called, Hibernate still thinks it is linked to the Volunteer instance. As cascade is set to ALL, this volunteer is removed when the organisation is deleted.
Try updating the organisation (to break the link with the volunteer) before deleting it.
The reference manual explains that: "You can even use cascade="all" to specify that all operations should be cascaded along the association. The default cascade="none" specifies that no operations are to be cascaded."
Its a little vague though what all means in this context because the delete-orphan cascade is explained later on in the text. I would suggest it really means all cascades. Found this: "Mapping an association (either a single valued association, or a collection) with cascade="all" marks the association as a parent/child style relationship where save/update/delete of the parent results in save/update/delete of the child or children."
Which is totally ok because in your case you don't want to cascade the delete at all as far as i understand.