Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Query.setMaxResults(0) seems to fail
Query.setMaxResults(0) seems to fail [message #628958] Fri, 24 September 2010 21:42 Go to next message
Tim is currently offline TimFriend
Messages: 21
Registered: June 2010
Junior Member
So I do a query like:

public List fetchResults(Query query, int start, int max) {
  return result = query.setFirstResult(start).setMaxResults(max).getResultList(); 


If I run with (5,2), I end up seeing a query from EL in the logs of the form:
SELECT id AS a1...FROM `tablename` LIMIT ?, ?
	bind => [5, 2]

but if I have (5,0), I end up with:
SELECT id AS a1...FROM `tablename`


There is obviously some code missing that does other stuff, but the key is that I end up getting a full result set from "tablename". I could see no indication in the javadoc that there was special functionality for setMaxResults() with a max of 0, so I'm assuming this is a bug.

EL 2.1.0 via JPA

Let me know if I am missing something. Otherwise, I'll file a bug.

--Tim
Re: Query.setMaxResults(0) seems to fail [message #629211 is a reply to message #628958] Mon, 27 September 2010 13:44 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Are you passing in a vlue of 0 for setMaxResults and expecting no results? A value <=0 for the max means there is no maximum, and so the limit (x,y) cannot be used. If the values used are not able to be used with the LIMIT function passed in, JDBC resultset filtering is used instead - this is decided within the specific DatabasePlatform subclass' printSQLSelectStatement method. Instead, the resultSet.absolute method is called if a value for the firstRows has been set.

Best Regards,
Chris
Re: Query.setMaxResults(0) seems to fail [message #629237 is a reply to message #629211] Mon, 27 September 2010 14:47 Go to previous messageGo to next message
Tim is currently offline TimFriend
Messages: 21
Registered: June 2010
Junior Member
Yes. I am expecting 0 results to be returned. This is using MySQL and testing from mysql, LIMIT 0, 0 works as I'd expect. So I'm not sure why Eclipselink takes a special action to strip the LIMIT clause on this request.

This is somewhat tied to my other question (Getting Results and Count from NamedQuery) about doing a result and a count listing for a query. In this case, we just want the count, so expect that if we do a max=0 call, we'll just get the count. We could obviously have a conditional in the code the skip the check altogether, but I'm looking at using MySQL's GET_COUNT() feature since I've not come up with a good alternative to getting the full count/result subset of a query.

Thanks.

--Tim
Re: Query.setMaxResults(0) seems to fail [message #635378 is a reply to message #629237] Tue, 26 October 2010 15:38 Go to previous message
Tim is currently offline TimFriend
Messages: 21
Registered: June 2010
Junior Member
Finally got around to submitting a bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=328730
Previous Topic:help with a ORDER BY COUNT (expression builder and reportquery)
Next Topic:Stored Procedure Call
Goto Forum:
  


Current Time: Fri Apr 19 01:19:40 GMT 2024

Powered by FUDForum. Page generated in 0.04036 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top