-->
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.  [ 5 posts ] 
Author Message
 Post subject: setting start row for ScrollableResultSet
PostPosted: Wed Dec 08, 2004 10:24 am 
Beginner
Beginner

Joined: Mon May 24, 2004 7:39 pm
Posts: 37
Location: Charlotte
Hibernate version: 2.1.6

This is a silly question but, I can't seem to figure this out:

I'm paging through many rows in a database and only want to show certain values (eg: rows 75 - 100 or something like that). Can somebody please tell me how to set a start row so I wouldn't have to scroll through 0-100 to get to 75-100? See the code below:

Session session = null;
try {
session = getSession();
Query query = session.createQuery(QUERY_STRING);
query.setMaxResults((PAGE_SIZE);
ScrollableResults rs = query.scroll();
rs.setRowNumber(rowNumber); // this doesn't work if the row number is higher than PAGE_SIZE
List results = new ArrayList(PAGE_SIZE);
boolean hasMoreRows = true;
for (int i=0; i<PAGE_SIZE; i++) {
if (!rs.next()) {
hasMoreRows = false;
break;
}
results.add(rs.get(0));
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 12:55 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
If you use setMaxResults(PAGE_SIZE) then hibernate will not return more than PAGE_SIZE

I think that mixed setMaxResults() and ScrollableResult is wrong
regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 1:08 pm 
Beginner
Beginner

Joined: Mon May 24, 2004 7:39 pm
Posts: 37
Location: Charlotte
Thanks, that solved my problem.

Joe


Top
 Profile  
 
 Post subject: what about setFirstResult in ScrollableResults
PostPosted: Tue Jan 13, 2009 8:01 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
I want to start the cursor at row 5000:

Code:

I found out, that using something like this:

ScrollableResults scrollResult= s.createQuery("from MyEntity m").setFetchSize(500).setFirstResult(5000).setMaxResults(500).setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);

is slower than using something like this:

ScrollableResults scrollResult= s.createQuery("from MyEntity m").setFetchSize(500).setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);

int scroll=0;
while (scrollResult.next() && scroll<500) {

//add to list
...

//clear cache
...

scroll++;

}


However the second approach does not start the cursor at position 5000, it starts at 0.

So I guess the setFirstResult(5000).setMaxResults(500). slows the fetching down. I use DB2, so I prefer to use ScrollableResults, but I want to begin fetching at row x. How can I set it via ScrollableResults ???


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 9:48 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
How can I proof, if a ScrollableResults is open? Something like:

ScrollableResults resultSet ;


Code:
if(!resultSet .isOpen())
{
resultSet = session.create...
}


any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.