Lets say I have two tables - "child" and "parent" with many-to-one relation. What I need is to delete child entries if parent record is deleted.
It is not a problem if I link child table from parent by creating one-to-many association in parent.hbm and set cascade="all-delete-orphan".
The problem is I don't want one-to-many relation on the parent side, so I created many-to-one on the child side. The reason for that is child table is pretty big and I don't want to extract hundreds of records every time I use parent. So my configuration looks like this:
child.hbm:
<many-to-one name="parent" class="com.example.Parent" column="parentid"/>
while parent.hbm has no associations with child.
The question is: How to make Hibernate delete records from child table when deleting a parent if a child is linked to a parent with many-to-one?
Thanks.