# Scrolling stored procedure cursors

**URL:** <https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885>\
**Category:** Hibernate ORM\
**Created:** [June 4, 2018, 6:44pm UTC](https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885 "2018-06-04T18:44:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nogueira.alvaro](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nogueira.alvaro](https://discourse.hibernate.org/u/nogueira.alvaro)\
**Post date:** [June 4, 2018, 6:44pm UTC](https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885/1 "2018-06-04T18:44:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 7:10pm UTC](https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885/2 "2018-06-04T19:10:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nogueira.alvaro](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@nogueira.alvaro](https://discourse.hibernate.org/u/nogueira.alvaro)\
**Post date:** [June 4, 2018, 7:50pm UTC](https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885/3 "2018-06-04T19:50:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 8:05pm UTC](https://discourse.hibernate.org/t/scrolling-stored-procedure-cursors/885/4 "2018-06-04T20:05:18Z")

</div>

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