Community
Participate
Working Groups
Build Identifier: 2.1.3 The firstResult property of an EJBQueryImpl cannot be reset to 0 once it has been previously set to a value > 0. Because setFirstResult(0) is internally represented by -1, the condition "if (firstResultIndex > -1)" does not hold hence it will not update the firstResult attribute of the database query: protected void propagateResultProperties() { DatabaseQuery databaseQuery = getDatabaseQueryInternal(); .... if (firstResultIndex > -1) { cloneSharedQuery(); readQuery = (ReadQuery) getDatabaseQueryInternal(); readQuery.setFirstResult(firstResultIndex); } } } Reproducible: Always Steps to Reproduce: 1. Create a JPQL Query using EntityManager.createQuery() 2. call setFirstResult(5) 3. execute the query using getResultList(). 4. call setFirstResult(0) 5. execute the query again using getResultList() => firstResult of 5 is still used
In EJBQueryImpl setFirstResultInternal(int startPosition), the code resets the internal firstResultIndex parameter to UNDEFINED (-1) if the startPosition is 0: if (startPosition == 0) { firstResultIndex = UNDEFINED; } else { firstResultIndex = startPosition; } This has the effect of not (re)-cloning the shared query and setting the first result on the clone; So the existing shared query with the previous firstResult value is executed. Solution is to simplify the code above to: firstResultIndex = startPosition;
Created attachment 206738 [details] Fix and testcase
Checked into trunk (2.4) at revision: 10361
Thanks for fixing this so quickly. Is there a chance of a backport to 2.3.2?
Checked into /branches/2.3/ at revision: 10362
Thanks, David.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink