Can I switch between cascade all and all-delete-orphon at runtime? If so, how? If not, what is the workaround?
The problem is that I have a many-to-one relationship (object A contains many B's) where I simply want to dissociate B from A (by setting the reference to null) while deleting B in other cases.
In the cases where I say cascade="all", saveOrUpdate() will actually disassociate B from A in the database properly if I go B.setA( null ). If I do A.getBs().remove( b ), Hibernate will delete b. This is working fine.
However, if I delete() object A, it won't delete any of the B's unless I use cascade="all-delete-orphan".
Now, I know I can delete the B's seperately. However, this causes a problem since the decision to delete B happens deep in the domain logic. If I want to continue using cascade="all", I will have to pull this logic out of the domain layer and move it up into the server layer where I can access Hibernate DAO objects.
Can anyone help me out? If you don't understand what I'm talking about, I'll try to clarify.
|