When paging is enabled, Hibernate inserts the following SQL as the LAST column in the SELECT statement:
, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as _hibernate_row_nr_
It appears Hibernate does this by searching for the word "FROM" and inserting before it.
However, if there exists a COLUMN with the word "FROM" in it, Hibernate inserts in the WRONG place, causing the following error message from SQL Server:
Incorrect syntax near the keyword 'as'.
To fix: look for the last occurrence of the word "FROM", not the first.
I will put together a Test project and attach at a later time.
Mac OS X 10.7. JBoss AS 7.1.1. Hibernate 4.1.3. Microsoft SQLJDBC 4.0. Microsoft SQL Server 2008.