Search code examples
nhibernateexceptionnhibernate-mapping

Why is NHibernate swallowing a SQL error from a lazy-loaded collection?


I've got an entity that maps a collection of components as follows:

<class name="TeacherResource" table="TeacherResource">
    <id name="TeacherResourceId">
        <generator class="guid"/>
    </id>

    <!-- irrelevant properties here... -->

    <bag name="HelpfulLinks" order-by="BogusColumnName">
        <key column="TeacherResourceId"/>
        <composite-element class="HelpfulLink">
            <property name="Href"/>
            <property name="Display"/>
         </composite-element>
    </bag>
</class>

At first I wasn't getting any data back for the collection, then I realized I had an incorrect column name in there for ordering the collection. NHibernate doesn't throw an exception, but if you view the property in the debugger after the property is lazy-loaded, there is an InnerException defined that indicates the error.

Why would NHibernate trap this error? I'm on .NET 4.0/NH 3.3.1.

NHibernate error


Solution

  • As already said, NHibernate never swallows Exceptions. Most likely that collection was loaded by data binding, in that case the data binding swallowed the exception.