Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363400

Summary: EJBQueryImpl setMaxResults can be incorrect with multiple calls
Product: z_Archived Reporter: David Minsky <david.minsky>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix & test none

Description David Minsky CLA 2011-11-09 18:11:04 EST
Found whilst investigating:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362804
(Need to file a separate bug, as the feature fix needs to be tracked and fixed independently)

Similar to 362804, setMaxResults can be incorrect / fail on subsequent calls, if invoked again on the same query with a different value.

Steps to Reproduce:
1. Create a JPQL Query using EntityManager.createQuery()
2. call setMaxResults(5)
3. execute the query using getResultList().
4. call setMaxResults(Integer.MAX_VALUE)
5. execute the query again using getResultList()

=> maxResults of 5 is still used

Code:

        EntityManager em = createEntityManager();
        clearCache();

        Query query = em.createQuery("SELECT e FROM Employee e");
        assertEquals("Query's maxResults should be Integer.MAX_VALUE", Integer.MAX_VALUE, query.getMaxResults());
        
        List controlList = query.getResultList();
        
        List shortenedResults = query.setMaxResults(5).getResultList();
        assertEquals("Full list should be shorter than the control results list", 5, shortenedResults.size());
        
        query.setMaxResults(Integer.MAX_VALUE);
        assertEquals("Query's max results should have been reset", Integer.MAX_VALUE, query.getMaxResults());
        
        List fullResults = query.getResultList();
        assertEquals("Full list should be the same as the control results list", controlList.size(), fullResults.size());
Comment 1 David Minsky CLA 2013-05-06 13:56:01 EDT
Created attachment 230531 [details]
Proposed fix & test
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:22:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink