0

using nhibernate and getNamedQuery, how can I handle a huge result set, without load all rows to a list? Let's suppose I need to do some logic with each row, but I don't need it after use it. I don't want to use pagination, because I can't change the source (a stored procedure).

Beetlejuice
  • 4,292
  • 10
  • 58
  • 84
  • Does this answer your question? [Using Hibernate's ScrollableResults to slowly read 90 million records](https://stackoverflow.com/questions/2826319/using-hibernates-scrollableresults-to-slowly-read-90-million-records) – Slava Medvediev Oct 05 '20 at 19:16

1 Answers1

0

When you say you don't want to use pagination, do you consider using setMaxResults() and setFirstResult() pagination?

Query query = session.getNamedQuery("storedProc");
query.setFirstResult(fromIndex);
query.setMaxResults(pageSize);

I'm not really sure you have any other option with Hibernate. There are all sorts of ways you can incorporate partitioning to split the work, but that's only after you've loaded the data that you want to partition.

Assuming you're doing some sort of logic against a row and storing in the DB, and seeing as you're already using stored procs, your best bet may be another stored proc. Alternatively, if you want to keep your logic outside of your DB, then you should be working off of tables rather than data from a stored proc.

Ryan
  • 46
  • 3