Scrolling stored procedure cursors


#1

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.


#2

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.


#3

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?


#4

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