Community
Participate
Working Groups
Build Identifier: EL 2.1.0 Probably easiest to point to the forum discussion: http://www.eclipse.org/forums/index.php?t=msg&th=197236&start=0&S=d5dfec1e841c62517ccb6136e8aab980 Generally, on MySQL, if you setMaxResults() to 0, you end up losing the LIMIT portion of the query altogether, resulting in all results being returned. This is very counterintuitive. "LIMIT #, 0" works as expected in MySQL (it returns 0 results) and so it should with EL/JPA. I can understand that a negative entry for MaxResults is undefined, but 0 seems very obvious. It should be documented in the Javadocs in any case as to the behavior of negative values being passed (and 0 if you do not agree that it should behave as expected or for some reason need to make a special case due to some other requirements). Reproducible: Always Steps to Reproduce: 1. query.setFirstResult(1).setMaxResults(2).getResultList(); 2. View the SQL generated. Should look like "...LIMIT ?, ? bind => [1, 2]". 3. query.setFirstResult(1).setMaxResults(0).getResultList(); 4. View the SQL generated. Should look like "..." with no LIMIT statement at all. Should look like "...LIMIT ?, ? bind => [1, 0]".
From the database perspective of how LIMIT works, this seems reasonable. But from the JPA setMaxResults perspective, it must work the same regardless of the database being used. JPA mandates that setMaxResults() throws IllegalArgumentException if the argument is negative, and is seems modeled after java.sql.Statement's setMaxRows method. Since there is no mechanism to unset maxResults once set, 0 was chosen instead keeping it inline with the previously mentioned setMaxRows method. I have changed this bug to be a documentation bug since I could not find this behavior mentioned in EclipseLink docs.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink