I was trying to retrive the first 5 records from the database by using the following query:
Code:
IQuery query = session.CreateQuery("FROM User AS user ORDER BY user.Id");
query.SetFirstResult(0)
query.SetMaxResults(5);
users = query.List();
But the line "users = query.List();" threw an exception:
Code:
NHibernate.ADOException: Co
uld not execute query ---> MySql.Data.MySqlClient.MySqlException: #42000You have an error in your SQ
L syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'NULL' at line 1
...
And I traced the query sent to mysql database server, the sql read:
Code:
select user0_.id as id, user0_.Role as Role, user0_.Password as Password, user0_.Name as Name, user0_.Description as Descript4_ from users user0_ order by user0_.id limit 5, NULL
Doesn't SetFirstResult support 0 as the position?
In this case, if I use SetFirstResult(1), the query.list() worked, but the returned list did not include the first record in the table.
Is this a bug in NHibernate? By the way, I am using nhibernate-0.9.0.0.