I have two classes, a creator class and a "file" class. Every "file" that is created has a creator, so we have a simple one-to-many association.
Code:
<class name="Creator" table="creator" lazy="true">
...
<set name="files"
inverse="true"
cascade="all-delete-orphan"
lazy="true">
<key>
<column
name="creator_id"
not-null="true"/>
</key>
<one-to-many class="Files"/>
</set>
</class>
and
Code:
<class name="Files" table="files" lazy="true">
...
<many-to-one
name="creator"
class="Creator"
foreign-key="fk_files_creator"
cascade="none">
<column
name="creator_id"
not-null="true"/>
</many-to-one>
</class>
What I need is to delete the creator an subsequently all the "files" he has created. This can be quite a huge number (many thousands).
I read that if I want Hibernate to take charge of cascading deletes, I must declare this association as bidirectional, using scaffolding code. So everytime a file is created, I have to add it to the set of files of it´s creators class.
I am not concerned with the efficiency of the deletion, but I am concerned with the efficiency of the scaffolding code. The sets can become very large, and I never need the set only in case I want to delete the creator and everything he has created.
Is that the correct way to manage deletion of dependent objects?
Thanks in advance,
Axel W. Berle