When upgrading from Hibernate 5.4.x to 5.6.x, our ability to stream resources with certain relationship scenarios stopped working. The attached minimal test case recreates the scenario.
The exception is:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not advance using next()
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.internal.ScrollableResultsImpl.convert(ScrollableResultsImpl.java:71)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:106)
at org.hibernate.query.internal.ScrollableResultsIterator.hasNext(ScrollableResultsIterator.java:33)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
at org.hibernate.query.spi.StreamDecorator.forEach(StreamDecorator.java:153)
at tst.oth.Test.main(Test.java:19)
Caused by: java.sql.SQLException: invalid cursor state: identified cursor is not open
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCResultSet.checkClosed(Unknown Source)
at org.hsqldb.jdbc.JDBCResultSet.next(Unknown Source)
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:101)
... 6 more
Caused by: org.hsqldb.HsqlException: invalid cursor state: identified cursor is not open
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
... 10 more