Sorry if this is obvious but we've been scratching our heads over this for several days now.
Consider three entities, Parent, Child and X:
Parent has a @OneToMany relationship to Child, set up to cascade deletes and orphan removal = true.
Child has a @ManyToOne relationship to Parent with optional = false, further the relationship is @NotNull and @JoinColumn has nullable = false.
X has a @ManyToOne relationship to Child with optional = true.
Here's what we'd ideally like to have happen when we delete a Parent. We'd like the delete to cascade and remove all Child rows that correspond to the deleted Parent. No problem so far. But we would also like any X that refers to any deleted Child to have the Child relationship nulled out. We do not want to delete any X, we merely want to null out the relationship. This is consistent with it being an 'optional' relationship.
How do we do this in Hibernate? Ideally we want it to be declarative so our business logic doesn't have to 'remember' to come null out these relationships. In fact, if we are to use cascading at all it really has to be declarative, given that there could be many levels of cascading before we come across an optional relationship to be nulled out.
Any hints? We're stumped ....
|