Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: how do I retrieve my entities from a ScrollableResults?

I do a query that returns a list of entities. How can I retrieve the entities from a ScrollableResults:

 Session s  = ....;
 Query q = s.createQuery("....") # returns 100000s rows
 ScrollableResults sr = q.scroll();
 sr.scroll(45999); # just a number
 Employee employee = ???

How do I get an employee in the last line of code

like image 369
flybywire Avatar asked Nov 12 '09 08:11

flybywire


2 Answers

try the get(0) method, or get()[0]

like image 57
Bozho Avatar answered Sep 27 '22 20:09

Bozho


Here's a link to API: ScrollableResults

get() returns the entire current row, get(index) returns object at index position without initializing the rest of them. There are also a bunch of convenience getXXX() methods that cast result to given type.

like image 20
ChssPly76 Avatar answered Sep 27 '22 21:09

ChssPly76