Que? No hablas
.NET, Cleverectomy, Spleen Vent October 6th, 2010
So, let me get this straight.
You cannot delete this object because you will go and recreate it because of its associations?
Have you thought that maybe…
.. And I know this is a VERY crazy thought…
That I want to GET RID OF THIS RECORD and its Associations?
nHibernate sucks. It sucked 4 years ago when I used it, and it sucks bigtime now too.
public void ActuallyDeleteEmail(int emailId)
{
ISQLQuery sqlQuery = Session.CreateSQLQuery(string.Format('DELETE FROM [TABLE] WHERE ID={0}', emailId.ToString()));
sqlQuery.ExecuteUpdate();
}
OH! MY! GOD!
YOU CAN ACTUALLY DELETE THE RECORD? WHO KNEW?


October 6th, 2010 at 5:10 pm
ehm, why not just do what it says, and delete the item from the association, so that nhibernate will delete the object for you.
October 6th, 2010 at 5:23 pm
Hace: So to get it to delete properly, I have to load up 5 collections (NOT efficient), delete the item from all 5 collections then re-save it?
Sounds like square wheels to me.
October 6th, 2010 at 9:38 pm
While I feel your pain as I did at one time had exactly the same problem you can’t blame your tools if you don’t actually understand how to use them properly.
October 7th, 2010 at 10:20 am
That means that a persisted object O has the object you’re trying to delete D in one of its collection C. As objects in collection C of O are saved in cascade, if you try to delete D it will be recognized as transient when NHibernate will check collection C and will be resaved.
In this case NHibernate’s behaviour is logical and the exception message is right, except the exception details sucks (which object causes the cascade ?)
In your case, it’s like putting a reference to null and complaining the memory was not garbage collected. The garbage collector requires all references to be set to null in order to free memory (or use weak references).
Don’t misunderstand me : I hate NHibernate, but for other reasons (no nested transaction, implicit update management totally sucks).
October 7th, 2010 at 10:22 am
And also self satisfaction from community (like Chris Nicola’s comment).