Hibernate version:Hibernate 2.1.2
Name and version of the database you are using:
MySql
I cannot find any feature related to the very useful "ON DELETE SET NULL" feature while I'm aware of the wonderful cascade="delete-orphan" feature, that can be mapped to the database as an "ON DELETE CASCADE" sentence.
Suppose I have a class/table named PARENT, while class/table CHILD contains objects that are related in an typical MANY-TO-ONE relationship.
Strong relations assert that when the parent is removed, all of his children must be removed also.
But many times this is not the case, and we have a "weak" relationship: when the PARENT is removed, the CHILDREN will silently loose the relationship to that object, because the children can in fact be orphan and their FK can be null. The problem is that if the application fails to set the FK to null, inevitably an exception will sooner or later happen when trying to retrieve the parent of the child.
ON DELETE SET NULL is the clause commonly used in the databases for this purpose. It magically releases the application from the task of reviewing the orphan rows to remove the link, by automatically setting the FK to NULL when the parent is removed.
Maybe this feature is anyhow considered inside Hibernate, but I coudn't find. Please anybody can help?
|