Scrolling stored procedure cursors

Hi guys,

I want to know if is possible to scroll stored procedure cursors in Hibernate using ScrollableResults or the java 1.8 Stream api.

The Hibernate scroll or stream is just a way to iterate over a JDBC ResultSet, so to prevent consuming it entirely before giving you the result back.

However, if you just return a REFCURSOR, you can iterate the associated ResultSet. You could also try to wrap it with a Spliterator too and consume the ResultSet using Java 8 streams.

1 Like

Thanks for the quick answer,

My problem is that a the stored procedure returns a large amount of data/rows via REF CURSOR, so I’m facing out of memory issues because all this data is being load in memory.

Using your sugested aproach of wrap the ResultSet with a Spliterator and consuming via streams solves the out of memory issues?

As long as you don’t iterate the entire Result Set, then yes.