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 ???