From 84726a577291236c0f0e1eba0f8ca13266e1277d Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Fri, 15 Dec 2023 10:50:42 +0100 Subject: [PATCH] HHH-17526 Throw correct exception when reading list results --- .../sql/results/spi/ListResultsConsumer.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/ListResultsConsumer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/ListResultsConsumer.java index 0a69881647..79718e5d5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/ListResultsConsumer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/ListResultsConsumer.java @@ -152,10 +152,9 @@ public class ListResultsConsumer implements ResultsConsumer, R> { final TypeConfiguration typeConfiguration = session.getTypeConfiguration(); final QueryOptions queryOptions = rowProcessingState.getQueryOptions(); RuntimeException ex = null; + persistenceContext.beforeLoad(); + persistenceContext.getLoadContexts().register( jdbcValuesSourceProcessingState ); try { - persistenceContext.beforeLoad(); - persistenceContext.getLoadContexts().register( jdbcValuesSourceProcessingState ); - final JavaType domainResultJavaType = resolveDomainResultJavaType( rowReader.getDomainResultResultJavaType(), rowReader.getResultJavaTypes(), @@ -207,13 +206,8 @@ public class ListResultsConsumer implements ResultsConsumer, R> { } } - try { - rowReader.finishUp( jdbcValuesSourceProcessingState ); - jdbcValuesSourceProcessingState.finishUp( readRows > 1 ); - } - finally { - persistenceContext.getLoadContexts().deregister( jdbcValuesSourceProcessingState ); - } + rowReader.finishUp( jdbcValuesSourceProcessingState ); + jdbcValuesSourceProcessingState.finishUp( readRows > 1 ); //noinspection unchecked final ResultListTransformer resultListTransformer = @@ -231,6 +225,7 @@ public class ListResultsConsumer implements ResultsConsumer, R> { try { jdbcValues.finishUp( session ); persistenceContext.afterLoad(); + persistenceContext.getLoadContexts().deregister( jdbcValuesSourceProcessingState ); persistenceContext.initializeNonLazyCollections(); } catch (RuntimeException e) {