|
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.
|