[ajug-members] Order of cascaded deletes with hibernate
Roy Wells
roy.g.wells at gmail.com
Wed Apr 27 12:30:17 EDT 2005
To any hibernate gurus out there.
I'm having an issue with cascaded deletes in hibernate. I would ask
this on the hibernate forum but that place gives answers at a snails
pace. In fact someone else allready asked it there and got ignored.
Here is the setup: Class "A" is a parent to both "B" and "C", and has
one-to-many collections of each. Class "C" has a unidirectional
many-to-one association with "B". The one-to-many collections from
"A" to both "B" and "C" are cascade delete.
The problem arrises when hibernate triggers cascade deletes from "A"
to "B" and "C" it needs to delete "C" first but it doesn't.
Is there a way to control the order in which deletes are cascaded in
hibernate. Otherwise I guess i'll just turn off the cascade deletes
and handle it with manual calls.
I also thought I might solve this with a Hibernate Interceptor, but
i've read that calling back into the session and triggering additional
operations from a hibernate interceptor is not supported.
Here is what the hibernate mapping essentially looks like.
<hibernate-mapping >
<class name="A">
<id name="id"><generator class="native" /></id>
<bag name="bList inverse="true" lazy="true" cascade="all">
<key column="a_id"/>
<one-to-many class="B"/>
</bag>
<bag name="cList inverse="true" lazy="true" cascade="all">
<key column="a_id"/>
<one-to-many class="C"/>
</bag>
</class>
<class name="B">
<id name="id"><generator class="native" /></id>
<many-to-one name="a" column="a_id" not-null="true"/>
</class>
<class name="C">
<id name="id"><generator class="native" /></id>
<many-to-one name="a" column="a_id" not-null="true"/>
<many-to-one name="b" column="b_id" not-null="true"/>
</class>
</hibernate-mapping>
More information about the ajug-members
mailing list