Ayende @ Rahien

Unnatural acts on source code

Debugging NHibernate

Today we had a problem with an NHibernate query that was failing which had quite stumped. Pulling the usual tricks didn't work, debugging NHibernate was problematic, since the failing query was damn complex, and I had no clear idea why this was failing. After a while, I decided that trying the top down approach will not work, and that I need more structure in finding out the issue.

Did I mentioned that the query was complex? The object model is big as well, and the query managed to touch just about all of it. Getting it slimmed down to a reproducable version was hard, because I wasn't sure what caused the issue, but eventually I managed to get it to fail the way I wanted it. (In the process I walked through parts of NHibernate that I haven't met before, interesting.

The end result are these tests (there is a reason that I know that C# has a 512 characters limits on identifiers):

  • CanMakeCriteriaQueryAcrossBothAssociationsWhenBothAssoicationsHasSameColumnKeyNameAndUsingPagingInSqlServer2005
  • CanLoadCollectionUsingLeftOuterJoinWhenBothCollectionsHasTheSameColumnKeyNameAndOneIsNull

I still don't have an answer, but now I have much harder questions...

This post is dedicated to Rinat, who says that she doesn't knows NHibernate, but can make queries so complex both NHibernate and SQL Server begs for mercy.

Comments

Casey
06/04/2007 02:43 PM by
Casey

There is a point at which comments once again become more useful than method names!!!!!

Ricardo Stuven
06/04/2007 07:54 PM by
Ricardo Stuven

...Or you can break the name in a subclass/method pair. Even better if you find commonalities:

[TestFixture]

public class CanMakeCriteriaQueryAcrossBothAssociations

{

[Test]

public void WhenSomePreconditionHappens1()

{

}

[Test]

public void WhenSomePreconditionHappens2()

{

}

}

Shaun McCarthy
06/05/2007 02:35 PM by
Shaun McCarthy

If you are using NUnit and making the names long to give a better description, you might want to consider using the Description attribute instead. This way you can keep your method names a little more succint and still give a decent error message in the output on failure

http://nunit.com/index.php?p=description&r=2.4.1

Comments have been closed on this topic.