From 9b32e9462aa59ac3f3ecf921e97515a45a8e08d4 Mon Sep 17 00:00:00 2001 From: Yoryos Valotasios Date: Sat, 30 Oct 2010 00:00:48 +0300 Subject: [PATCH] HHH-2655: bug fix: row_number() function is not zero and so we must increament the given limit and offset by one --- .../main/java/org/hibernate/dialect/SQLServer2008Dialect.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java index 2e4d998ee2..e1d8e505a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/SQLServer2008Dialect.java @@ -85,7 +85,9 @@ public class SQLServer2008Dialect extends SQLServerDialect { // Wrap the query within a with statement: sb.insert(0, "WITH query AS (").append(") SELECT * FROM query "); sb.append("WHERE __hibernate_row_nr__ "); - if (offset > 0) sb.append("BETWEEN ").append(offset).append(" AND ").append(limit); + + // The row_number() function is not zero based and so we must increment the offset and limit by one + if (offset > 0) sb.append("BETWEEN ").append(offset + 1).append(" AND ").append(limit + 1); else sb.append(" <= ").append(limit); // As mentioned before I don't think that we really need this last order by clause