Ok, I've been reading through all of the manuals for the fourth time, but I cannot find a definitive conclusion on my current issue.
I have a parent child relation like this:
grandparent 1 ---- 0..* parent 1 ----- 0..* child
So all the classes have a bi-directional relationship with both their chhildren and their parent.
The thing I want to accomplish is the following.
If the class "parent" is passed to the DAO code I want to save the following:
- fields in the class "parent"
- relationship with "grandparent"
I do not want to save these values:
- fields in "grandparent"
- relationship with "child"
- fields in "child"
If parent is deleted I do want to remove all children. (same for grandparent)
This is all due to the fact that security is always checked for one layer, so the dao will check if you may add a parent to grandparent, but will not check if you may edit all the children to save database queries.
So in order to delete a child, you will have to remove it from the db, and the relationship with the parent should be removed aswell.
If you remove a child from the set in parent and save the parent, nothing should happen.
Is this possible with a combination of inverse and cascade? I was thinking of the following:
grandparent -> parent
inverse = true
cascade = delete
parent -> grandparent
inverse = false
cascade = none
not-null = true
parent -> child
inverse = true
cascade = delete
child -> parent
inverse = false
cascade = none
not-null = true
This way I think it should be possible to return a parent with an incomplete list of children and call save to the parent without actually deleting any children, while still updating the reference to grandparent. Am I correct?
|