A strange bug in NHibernate 2.1 - 3.2.0

added by lukian
1/16/2012 4:22:39 PM

0 Kicks, 201 Views

In a previous post I described a technique to insert query hints into NHibernate query with the use of comments. Testing this code in a real project lead to a strange exception when I issue queries with ICriteria. Error message: "The query should start with ‘SELECT’ or ‘SELECT DISTINCT’" This happens because ICriteria queries inserts comments inside the query and if you enable comments to flow into the query with the setting use_sql_comments something weird happens when you use SetMaxResults to issue a paginated query. If you look into the NHibernate code that is throwing the exception you find this function in the Sql Dialect