Skip to content

Commit

Permalink
[hibernate#1342] Fix pagination for MSSQL queries without Order by
Browse files Browse the repository at this point in the history
The MSSQL dialect generates set the pagination in the query
in different ways depending on the presence of the order by
clause.
  • Loading branch information
DavideD committed Jun 17, 2022
1 parent f213c56 commit 662452a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public String processLimit(String sql, Object[] parameterArray, boolean hasOffse
shiftValues( parameterArray );
return sqlProcessed;
}

// Not order by, no filter
// See SQLServer2005LimitHandler#processSql
int paginationFilterPos = sql.lastIndexOf( "__row__ >= ? and __row__ < ?" );
if ( paginationFilterPos > -1 ) {
sql = sql.substring( 0, paginationFilterPos );
sql += "__row__ >= @P" + index++ + " and __row__ < @P" + index++;
}
return sql;
}

Expand Down

0 comments on commit 662452a

Please sign in to comment.