From d7d2294bd9a990c3edec71731466ca964698f922 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 3 Apr 2024 18:48:41 +0200 Subject: [PATCH] HHH-17826 ResultSet closed while scrolling results --- .../hibernate/internal/ScrollableResultsImpl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java index a0b187ea53..f225abd21d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java @@ -129,16 +129,20 @@ public class ScrollableResultsImpl extends AbstractScrollableResults { loadContexts.register( getJdbcValuesSourceProcessingState() ); persistenceContext.beforeLoad(); try { - currentRow = getRowReader().readRow( getRowProcessingState(), getProcessingOptions() ); + try { + currentRow = getRowReader().readRow( getRowProcessingState(), getProcessingOptions() ); - getRowProcessingState().finishRowProcessing( true ); - getJdbcValuesSourceProcessingState().finishUp( false ); + getRowProcessingState().finishRowProcessing( true ); + getJdbcValuesSourceProcessingState().finishUp( false ); + } + finally { + persistenceContext.afterLoad(); + } + persistenceContext.initializeNonLazyCollections(); } finally { - persistenceContext.afterLoad(); loadContexts.deregister( getJdbcValuesSourceProcessingState() ); } - persistenceContext.initializeNonLazyCollections(); afterScrollOperation(); }