JPA: what is the proper pattern for iterating over large result sets?
Posted
by
Caffeine Coma
on Stack Overflow
See other posts from Stack Overflow
or by Caffeine Coma
Published on 2011-02-21T15:13:30Z
Indexed on
2011/02/21
15:25 UTC
Read the original article
Hit count: 243
Let's say I have a table with millions of rows. Using JPA, what's the proper way to iterate over a query against that table, such that I don't have all an in-memory List with millions of objects?
I suspect that the following will blow up if the table is large:
List<Model> models = entityManager().createQuery("from Model m", Model.class).getResultList();
for (Model model : models)
{
// do something with model
}
Is pagination (looping and manually updating setFirstResult()
/setMaxResult()
) really the best solution?
© Stack Overflow or respective owner