I have an object tree in which an object has several collections, mapped with cascade-delete-orphans, this object is also part of a collection.
Issuing:
Code:
session.Delete(object obj);
works ok, but when i try to commit i get an NHibernateException:
Quote:
Flush during cascade is dangerous - this might occur if an object as deleted and then re-saved by cascade
But if after this, I request a new session and issue:
Code:
session.Delete(object obj);
session.Commit();
This time the operation doesn't fail with an NHibernateException and the database executes the deletes consistently.
I've debugged the code and found:
SessionImpl.Delete(object obj)
Code:
entry.Status = Status.Deleted;
In the Delete method the entries for the deleted objects are set to Status.Deleted but
In SessionImpl.PreFlushEntities():
Code:
Status status = entry.Status;
if( status != Status.Loading && status != Status.Gone && status != Status.Deleted )
{
object obj = me.Key;
cascading++;
try
{
Cascades.Cascade( this, entry.Persister, obj, Cascades.CascadingAction.ActionSaveUpdate, CascadePoint.CascadeOnUpdate );
}
finally
{
cascading--;
}
}
The entry.Status is Status.Loaded although it was already set to Status.Deleted by the Delete method. :?
I don't know if there might be a bug somewhere because it seems to me that I have two different instances of the same entry instead of only one.