We have some code pattern that used to work in Hibernate 5 but fails on Hibernate 6.
The code iterates a ScrollableResults in the usual way by calling next/get in a while loop. Now the second call to next 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.
It looks like I’d need to wrap the loop within beginTransaction/commit to make it work.
Is it expected that any usage of scrollable results should now be within a transaction, or is there any other solution? Was there some change in Hibernate 6 in this respect, while in Hibernate 5 it was not required? I could not find a statement in a migration document.
Hibernate 6 has 5 different minor versions so far, so you have to be a bit more specific about the version you use. Lots of bugs were fixed, so please try again with 6.4.4.Final. If you still have a problem, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.
Sorry I wasn’t specific, this is happening with 6.4.4.Final as well. I didn’t raise a jira as I wasn’t really sure if this was a bug or rather an intended change which ended up in a different behavior in my case.
Looking more in depth, it seems this behavior actually 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.