Fixed
Details
Assignee
Brett MeyerBrett MeyerReporter
Furkan KAMACIFurkan KAMACILabels
Components
Affects versions
Priority
Minor
Details
Details
Assignee
Brett Meyer
Brett MeyerReporter
Furkan KAMACI
Furkan KAMACILabels
Components
Affects versions
Priority
Created February 20, 2014 at 11:59 AM
Updated May 5, 2022 at 10:45 AM
Resolved May 5, 2022 at 10:45 AM
When I set setMaxResults to 0 I expected that it works as like LIMIT 0 of SQL query syntax. However it returns all records. I've checked the code and I saw that at org.hibernate.internal.AbstractQueryImpl:
public Query setMaxResults(int maxResults) {
if ( maxResults < 0 ) {
// treat negatives specically as meaning no limit...
selection.setMaxRows( null );
}
else {
selection.setMaxRows( maxResults);
}
return this;
}
It says that will set selection's maxRows property with 0 because of maxResults is greater or equal to 0 (maxRows is 0).
However there is a line of code at org.hibernate.dialect.pagination.LimitHelper
public static boolean hasMaxRows(RowSelection selection) {
return selection != null && selection.getMaxRows() != null && selection.getMaxRows() > 0;
}
so it checks selection.getMaxRows() > 0 and does not check selection.getMaxRows() >= 0 This is a mismatch with previous class. If I change it to selection.getMaxRows() >= 0 it will work as like LIMIT 0 of SQL query syntax but I think that this is not expected. So I've changed the comparison criteria of AbstractQueryImpl and fixed comment.