I'm not a specialist of Hibernate, but there are some "cascade" options that you might find useful. Something like that:
<set name="children" inverse="true" cascade="save-update">
  <key name="PARENT_ID" on-delete="cascade">
  <one-to-many class="Child">
<set>
(please note the cascade="save-update" instead of cascade="all")

According to http://eddii.wordpress.com/2006/11/16/hibernate-on-deletecascade-performance/, with these settings Hibernate will efficiently use "ON DELETE CASCADE" at DB level. Without requiring to load all the objects to be deleted in the application first.


I don't know if Hibernate is able to use this feature this with Derby. If you find out, please, let us know!

Sylvain.


Preben Mikael Bohn a écrit :
Hi Sylvain

Derby supports cascade delete as part of the referential action specified at
table's creation time.
Then, when using a DELETE statement to remove row(s) from the referenced
table, the DELETE operation is propagated to the dependent table. Here is an
example:

OK, I see...

The problem though is that I don't know the structure of the tables
and I need to do a batch delete of several tables. I could of course
go through each of the tables and manually find dependent tables but
since I have to do this over and over again during development where
the table structure changes significantly (automatically generated by
Hibernate) this is really not an option...

On the other hand I could go over all the tables and try to delete
them in a loop until all data are deleted (although some delete
statements would still fail)... That would probably do the trick...
:-)

Best regards Preben




--
Website: http://www.chicoree.fr


Reply via email to