Hi,
In Hibernate3.1x it is possible to use DML-style for update/insert/delete operations on Hibernate entities. Suppose I have an object graph that I need to remove by deleting parent object.
In non-DML style it would look like:
Code:
session.delete(objectInstance)
which would cause cascade deletion for all child objects with cascade="all" in mapping file.
Correspondent DML-style will be similar to this:
Code:
String hqlUpdate = "delete SomeObject someObject where someObject.id = :id";
session.createQuery(hqlUpdate).setLong("id", realId).executeUpdate();
This would produce SQL, similar to the following:
Code:
DELETE FROM SOME_OBJECT WHERE SOME_OBJECT_ID=?
This would cause runtime error due to possible database data integrity constraint (assume no cascade propagation constrains on database level).
The question is - how to tell Hiberante to traverse whole object graph for cascade update/delete in DML-style update/delete impl. ?