I need to delete a parent when there are no children that reference it. Is this possible in Hibernate? (actually I’m using fluent nhibernate but I presume the answer is the same)
e.g. I have many customers from different different companies. when I delete the last customer for a company I want to automatically delete the company details too.
Unlike a normal parent-child relationship, I don’t consciously select to delete the company. as far as the user is concerned he’s just deleting a customer; deleting an unreferenced company is just a by-product of this.
Hibernate won’t do it magically for you. You’ll have to implement it yourself: