Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate,Query,setMaxResults

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Does the setMaxResults() method Query_setMaxResults mimic (the way resultsets are retrieved, processed) Statement.setMaxRows(int) Statement_setMaxRows or Statement.setFetchSize(int) Statement_setFetchSize?

Or does it do something different?

[ November 20, 2006: Message edited by: Santosh Ramachandrula ]
[ November 20, 2006: Message edited by: Santosh Ramachandrula ]
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it does something different.
It tells the DB to return only that many rows by adding something to your SQL statement (e.g. LIMIT keyword but this is verry DB depending)

pascal
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the query that we are setting setMaxResults()

So how does it exactly work? like...

1. It does the cartesian product (I know it has to)
2. Retrieve the complete ResultSet from DB or not?
3. Except for the 'n' number of row drop the rest?
4. At what point of execution does Hibernate decide that I have to get these many number of rows?
5. How does it work?

[ November 21, 2006: Message edited by: Santosh Ramachandrula ]
[ November 22, 2006: Message edited by: Santosh Ramachandrula ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

2. Retrieve the complete ResultSet from DB or not?
3. Except for the 'n' number of row drop the rest?
4. At what point of execution does Hibernate decide that I have to get these many number of rows?
5. How does it work?

2. No. Just a result set of the size you specify as max or less.
3. The SQL doesn't return any more than the specified number of results. How this is implemented is up to the database.
4. When it constructs the SQL query, since it uses vendor-specific limiting keywords to do this.
5. Hibernate asks the database to limit the results returned by the query. It does this via the dialect, which uses whatever database-specific mechanism there is to do this (so for SQL Server it will do somthing like "select top n * from table", Oracle will do "select * from table where rownum < n", MySQL will do "select * from table limit n" etc). Then it just returns what the database returns.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pascal and Paul Thanks a lot for your response
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic