-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: SQLQuery - Number of row fetched
PostPosted: Sun May 25, 2008 3:29 pm 
Newbie

Joined: Sun May 25, 2008 3:14 pm
Posts: 1
I've had to execute a query using SQL rather than HQL or Criterions.

The query will typically return in excess of 3000 rows. Typically I'll only been interested in the first X number of rows (X is unknown and is determined when processing the results returned). The problem I have is that when I execute the query ...

Code:
SQLQuery query = session.createSQLQuery();
List<Object[]> results = query.list(); // Fetches everything

for (Object[] row : results) {
// Process the row returned
}


... Hibernate seems to try and retrieve (and populate into objects) all the rows returned by the query even though I'll only be interested in the first X rows. Is there a way you can configure the number of rows populated and retrieved at a time so that the results are retrieved in batches? i.e. retrieve me 50 rows at a time.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 25, 2008 4:06 pm 
Newbie

Joined: Sun Aug 26, 2007 2:09 pm
Posts: 4
Location: INDIA
Have you tried
public Query setMaxResult(int maxResult) method of Query interface.
By default there is no limit to number of rows retrieved.
It would limit the number of rows.

Also you can try scroll() method of query interface which will give you scrollable result .
Then you can use method provided by ScrollableResults intrface to manipulate the result.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.