This is STILL not working in 3.2.x . . . I have found numerous posts on the web pertaining to this problem, dating back to 2004, but it appears the issue has still not been addressed.
Here are some of the issues logged:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2263
http://opensource.atlassian.com/projects/hibernate/browse/ANN-598
http://opensource.atlassian.com/projects/hibernate/browse/HB-1094
The interesting thing here . . . notice on HB-1094, Gavin King mentions that this has been added to the Hibernate 3 branch. If you read Section 5.1.19 of the Hibernate Docs, it states . . .
Quote:
We recommend that for systems where delete performance is important, all keys should be defined on-delete="cascade", and Hibernate will use a database-level ON CASCADE DELETE constraint, instead of many individual DELETE statements. Be aware that this feature bypasses Hibernate's usual optimistic locking strategy for versioned data
This would imply that by simply placing
on-delete="cascade" to a key on, say, a one-to-many set, this should add ON DELETE CASCADE to the DDL generated by way of HBM2DDL . . . but it doesn't!!!
Here is a one-to-many I have set up, where I want ON CASCADE DELETE to apply to the foreign key, but it is not being added to the DDL:
Code:
<class name="com.xrite.ind.core.Group" table="tblGroup" >
<id name="Id" type="long">
<column name="groupID" />
<generator class="native" />
</id>
<set name="userGroups" lazy="true" table="tblUserGroup_DataGroup" inverse="true" >
<key column="groupID" on-delete="cascade"/>
<many-to-many column="userGroupID" class="com.xrite.ind.backcheck.users.UserGroup"/>
</set>
if I take the on-delete="cascade" off and add cascading on the set, I get individual
delete statements, which also results in ALL of the objects being loaded(their children and their children, and so on) and subsequently deleted(which takes forever and requires a lot of memory).
Is there a way to get ON CASCADE DELETE added to HBM2DDL generated DDL or no?