Skip to content

Commit ddfce2a

Browse files
dreab8beikov
authored andcommitted
HHH-16120 Error advancing (next) ResultSet position
1 parent f81426c commit ddfce2a

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ else if ( !session.isConnected() ) {
286286
Whenever the collection lazy loading is triggered during the loading process,
287287
closing the connection will cause an error when RowProcessingStateStandardImpl#next() will be called.
288288
*/
289-
if ( !session.isTransactionInProgress() && session.getPersistenceContext().isLoadFinished() ) {
289+
final PersistenceContext persistenceContext = session.getPersistenceContext();
290+
if ( !session.isTransactionInProgress()
291+
&& ( !persistenceContext.hasLoadContext()
292+
|| ( persistenceContext.hasLoadContext()
293+
&& persistenceContext.getLoadContexts().isLoadingFinished() ) ) ) {
290294
session.getJdbcCoordinator().afterTransaction();
291295
}
292296
}

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ public LoadContexts getLoadContexts() {
201201
return loadContexts;
202202
}
203203

204+
@Override
205+
public boolean hasLoadContext() {
206+
return loadContexts != null;
207+
}
208+
204209
// @Override
205210
// public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
206211
// if ( unownedCollections == null ) {

hibernate-core/src/main/java/org/hibernate/engine/spi/PersistenceContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public interface PersistenceContext {
5858
*/
5959
LoadContexts getLoadContexts();
6060

61+
default boolean hasLoadContext() {
62+
getLoadContexts();
63+
return true;
64+
}
65+
6166
// /**
6267
// * Add a collection which has no owner loaded
6368
// *

hibernate-core/src/main/java/org/hibernate/sql/results/spi/LoadContexts.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public void deregister(JdbcValuesSourceProcessingState state) {
4848
}
4949
}
5050

51+
public boolean isLoadingFinished() {
52+
return jdbcValuesSourceProcessingStateStack.depth() == 0;
53+
}
54+
5155
public LoadingEntityEntry findLoadingEntityEntry(EntityKey entityKey) {
5256
return jdbcValuesSourceProcessingStateStack.findCurrentFirst(
5357
state -> state.findLoadingEntityLocally( entityKey )

0 commit comments

Comments
 (0)