When I limit a query by setting the maximum rows to INTEGER.MAX_VALUE and set a first row > 0, (I admit that's not very "limiting") the following messages are logged:
2009-07-10 10:43:43,348 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 20000, SQLState: XJ063
2009-07-10 10:43:43,348 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Invalid parameter value '-2,147,483,647' for
Statement.setMaxRows(int maxRows). Parameter value must be >= 0.
By debugging I ended up in /core/trunk/core/src/main/java/org/hibernate/loader/Loader.java in the setMaxRows method where
RowSelection.maxRows == INTEGER.MAX_VALUE and RowSelection.firstRow == 2
Here is the code for our revision (3.3.0 SP1):
Code:
private void setMaxRows(
final PreparedStatement st,
final RowSelection selection) throws SQLException {
if ( hasMaxRows( selection ) ) {
st.setMaxRows( selection.getMaxRows().intValue() + getFirstRow( selection ) );
}
}
Revision 17061 is almost the same:
Code:
private void setMaxRows(
final PreparedStatement st,
final RowSelection selection) throws SQLException {
if ( hasMaxRows( selection ) ) {
st.setMaxRows( selection.getMaxRows().intValue() + interpretFirstRow( getFirstRow( selection ) ) );
}
}
The by adding RowSelection.maxRows and RowSelection.firstRow, int data type overflows to a negative value and setMaxRows of course complains.
I didn't find this behavior mentioned in the forums or JIRA.
Larry