Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363400 - EJBQueryImpl setMaxResults can be incorrect with multiple calls
Summary: EJBQueryImpl setMaxResults can be incorrect with multiple calls
Status: ASSIGNED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 18:11 EST by David Minsky CLA
Modified: 2022-06-09 10:22 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix & test (2.85 KB, patch)
2013-05-06 13:56 EDT, David Minsky CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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