We have an existing data model that we're try to model using Hibernate 3. Our object model contains Sponsor objects, each of which has a one-to-many relationship to PlanYear objects and a one-to-many relationship to Policy objects. Sponsor controls the lifecycle of both of these relationships using a cascade style of "all". Policy also contains a many-to-one relationship with a PlanYear (also linked to the Sponsor), but it does not control the lifecycle of the PlanYear (hence the cascade style is "none"). Policy must contain a PlanYear, thus the many-to-one relationship not-null is set to "true".
We have a test case where we have created a object graph of a single Sponsor object, PlanYear objects, and Policy objects and when we try to delete the Sponsor (and cascade the delete to Policy and PlayYear relationships), we have problems with the PlanYear objects are being deleted before the Policy objects are deleted, thus causing not-null constraint problems in Hibernate (or in the database if the not-null constraint is relaxed in the Hibernate mapping of Policy).
Is there any way to control the delete order within the Sponsor mapping to correctly remove the Policies before removing the PlanYears? Interesting, we're also evaluating TopLink and it has the same problem with our data model. The person doing the TopLink spike seems to think that TopLink has mapping logic to take care of this. We'll see.
Kind regards,
-- chris bartling --
|