Fix ScrollableResultsImpl not initializing non lazy collections

This commit is contained in:
Andrea Boriero 2021-07-14 16:38:46 +02:00
parent ba5d90d116
commit 3aa875b037
3 changed files with 22 additions and 17 deletions

View File

@ -127,6 +127,11 @@ private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
getProcessingOptions() getProcessingOptions()
); );
getRowProcessingState().finishRowProcessing();
getJdbcValuesSourceProcessingState().finishUp();
getRowProcessingState().getSession().getPersistenceContext().initializeNonLazyCollections();
afterScrollOperation(); afterScrollOperation();
} }

View File

@ -16,9 +16,7 @@
import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.service.spi.EventListenerGroup; import org.hibernate.event.service.spi.EventListenerGroup;
import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.PostLoadEvent; import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PostLoadEventListener; import org.hibernate.event.spi.PostLoadEventListener;
import org.hibernate.event.spi.PreLoadEvent; import org.hibernate.event.spi.PreLoadEvent;
@ -164,7 +162,6 @@ public SharedSessionContractImplementor getSession() {
@Override @Override
public void finishUp() { public void finishUp() {
try {
// for arrays, we should end the collection load beforeQuery resolving the entities, since the // for arrays, we should end the collection load beforeQuery resolving the entities, since the
// actual array instances are not instantiated during loading // actual array instances are not instantiated during loading
finishLoadingArrays(); finishLoadingArrays();
@ -177,10 +174,6 @@ public void finishUp() {
postLoad(); postLoad();
} }
finally {
executionContext.getSession().getPersistenceContext().getLoadContexts().deregister( this );
}
}
private void postLoad() { private void postLoad() {
if ( loadingEntityMap == null ) { if ( loadingEntityMap == null ) {
@ -209,6 +202,7 @@ private void postLoad() {
); );
} }
); );
loadingEntityMap = null;
} }
private void finishLoadingArrays() { private void finishLoadingArrays() {
@ -247,7 +241,7 @@ private void finishLoadingCollections() {
loadingCollectionEntry.finishLoading( getExecutionContext() ); loadingCollectionEntry.finishLoading( getExecutionContext() );
} }
loadingCollectionMap.clear(); loadingCollectionMap = null;
} }
} }

View File

@ -114,7 +114,13 @@ public List<R> consume(
rowProcessingState.finishRowProcessing(); rowProcessingState.finishRowProcessing();
} }
} }
try {
jdbcValuesSourceProcessingState.finishUp(); jdbcValuesSourceProcessingState.finishUp();
}
finally {
persistenceContext.getLoadContexts().deregister( jdbcValuesSourceProcessingState );
}
return results; return results;
} }
finally { finally {