From 239014db35878acf397a02533d432c6140325ff9 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 d15cf48aa4..a50873ef19 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(); - getJdbcValuesSourceProcessingState().finishUp( false ); + getRowProcessingState().finishRowProcessing( ); + getJdbcValuesSourceProcessingState().finishUp( false ); + } + finally { + persistenceContext.afterLoad(); + } + persistenceContext.initializeNonLazyCollections(); } finally { - persistenceContext.afterLoad(); loadContexts.deregister( getJdbcValuesSourceProcessingState() ); } - persistenceContext.initializeNonLazyCollections(); afterScrollOperation(); }