ResultSet closed while scrolling results

Description

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 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.

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

Activity

Show:

Andrea Boriero April 11, 2024 at 10:18 AM
Edited

Hi ,

here you can see the changes.

Anyway my advice is to always use transactions.

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

Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created March 8, 2024 at 1:24 PM
Updated April 12, 2024 at 6:22 PM
Resolved April 8, 2024 at 2:27 PM