Hi again,
I checked the code for the SQLServer dialect and as you say it is just limiting the query with TOP. SQLServer does not support a limit functionality. If you would switch to another database which supports it (PostgreSQL, MySQL, Oracle, ...) you would get the expected results.
How would your approach with ROW_NUMBER() look like? Note though that ROW_NUMBER() is a function new in SQLServer 2005. Currently there is only one single SQLServerDialect in Hibernate. If your approach is feasible one would have to split the dialects in order to integrate this approach. Maybe you want to continue this discussion on the Hibernate Core forum since it is not entity manager related?
Last but not least you could look into using scrollable resultsets. Have a look at these wiki pages:
-
http://www.hibernate.org/314.html
-
http://www.hibernate.org/248.html
If you are using the jTDS driver for SQLServer you might get a real performance boost.
--Hardy