Common problems with Named SQL queries

Named SQL queries in NHibernate is a way that you can put a native SQL query in a .hbm.xml file and executed it via IQuery and GetNamedQuery. By working with this feature you may encounter some errors and exceptions. Here I have gathered some common problems that I have seen by myself.

NHibernate.MappingException : unknown class

Occurs when return clause of XML mapping file defines a class that is not defined in the domain. This error does not allow anything work.
—-

NHibernate.HibernateException : Errors in named queries: {QUERY_NAME}

Occurs when return clause of XML defines a class that the class exists but its mapping does not exists. This error does not allow anything work.

NHibernate.ADOException : could not execute query ****
System.IndexOutOfRangeException : COLUMN_NAME

When a column is defined in return clause but does not exists in select clause of query.

NHibernate.ADOException : could not execute query
System.IndexOutOfRangeException : Recstatus

When named query return an entity that is inheriting from another entity but sql query does not return all columns that is used by both entity itself and its parent.