ResultSet closed while scrolling results
Description
Activity
Show:

Andrea Boriero April 11, 2024 at 10:18 AMEdited

Marco Pelagatti April 11, 2024 at 9:57 AM
Hi ,
I notice this item has been marked as resolved. I’m curious what the fix was on this one? Are we not required to wrap a scroll in a transaction anymore?
Thanks
We have some code pattern that used to work in Hibernate 5.4 but fails on Hibernate 6.4.4.
The code iterates a ScrollableResults in the usual way by calling
next
/get
in a while loop. Now the second call tonext
fails because the ResultSet has been closed in the meantime, even if the loop itself does nothing.We notice it happening mainly if the entity has some entity linked to it, like in a
@OneToMany
association.Example entities:
Example query:
It looks like I now need to wrap the loop within
beginTransaction
/commit
to make it work.It seems this behavior changed somewhere along Hibernate 5 history. It worked fine on 5.4.x, stopped working later in 5.5/5.6 series, and it is not working now in 6.4.4.
I have put reproducers at this repo