ScrollableResults closed unexpectedly when performing another query inside scroll loop

Description

Using a second query while scrolling causes the ScrollableResults to be closed.

Minimal example:

Perhaps I am not supposed to unwrap the JPA2 query like that?
WIth Hibernate 5.1.0 and the following code to obtain a ScrollableResults, the example code works as expected:

However, running 5.4.18, it does not appear to matter what query I issue inside the loop, it will close the result set.

The resulting exception from 5.4.18:

Thanks for any help!

Addendum:
I have tested the following code using the JPA2 getResultStream(), and it also produces the same exception:

The exception from using getResultStream():

Environment

m5.4.18, 5.4.19
CentOS 7, Fedora 30
OpenJDK 1.8.0
Postgres 11

Assignee

Unassigned

Reporter

Jamie Strachan

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.1.0

Components

Affects versions

Priority

Major
Configure