HHH-16184 Two queries are execute to initialize empty collections
This commit is contained in:
parent
66ef965320
commit
fb901051ca
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.internal;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.sql.results.internal.RowProcessingStateStandardImpl;
|
||||
import org.hibernate.sql.results.jdbc.internal.JdbcValuesSourceProcessingStateStandardImpl;
|
||||
|
@ -122,6 +123,10 @@ public class ScrollableResultsImpl<R> extends AbstractScrollableResults<R> {
|
|||
return;
|
||||
}
|
||||
|
||||
final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
|
||||
|
||||
persistenceContext.beforeLoad();
|
||||
try {
|
||||
currentRow = getRowReader().readRow(
|
||||
getRowProcessingState(),
|
||||
getProcessingOptions()
|
||||
|
@ -129,8 +134,11 @@ public class ScrollableResultsImpl<R> extends AbstractScrollableResults<R> {
|
|||
|
||||
getRowProcessingState().finishRowProcessing();
|
||||
getJdbcValuesSourceProcessingState().finishUp();
|
||||
|
||||
getRowProcessingState().getSession().getPersistenceContext().initializeNonLazyCollections();
|
||||
}
|
||||
finally {
|
||||
persistenceContext.afterLoad();
|
||||
}
|
||||
persistenceContext.initializeNonLazyCollections();
|
||||
|
||||
afterScrollOperation();
|
||||
}
|
||||
|
|
|
@ -291,9 +291,11 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
final SharedSessionContractImplementor session = executionContext.getSession();
|
||||
|
||||
final boolean stats;
|
||||
long startTime = 0;
|
||||
final StatisticsImplementor statistics = executionContext.getSession().getFactory().getStatistics();
|
||||
final StatisticsImplementor statistics = session.getFactory().getStatistics();
|
||||
if ( executionContext.hasQueryExecutionToBeAddedToStatistics()
|
||||
&& jdbcValues instanceof JdbcValuesResultSetImpl ) {
|
||||
stats = statistics.isStatisticsEnabled();
|
||||
|
@ -359,7 +361,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
|
|||
|
||||
final T result = resultsConsumer.consume(
|
||||
jdbcValues,
|
||||
executionContext.getSession(),
|
||||
session,
|
||||
processingOptions,
|
||||
valuesProcessingState,
|
||||
rowProcessingState,
|
||||
|
|
|
@ -153,6 +153,7 @@ public class ListResultsConsumer<R> implements ResultsConsumer<List<R>, R> {
|
|||
final QueryOptions queryOptions = rowProcessingState.getQueryOptions();
|
||||
RuntimeException ex = null;
|
||||
try {
|
||||
persistenceContext.beforeLoad();
|
||||
persistenceContext.getLoadContexts().register( jdbcValuesSourceProcessingState );
|
||||
|
||||
final JavaType<R> domainResultJavaType = resolveDomainResultJavaType(
|
||||
|
@ -221,8 +222,8 @@ public class ListResultsConsumer<R> implements ResultsConsumer<List<R>, R> {
|
|||
}
|
||||
finally {
|
||||
try {
|
||||
|
||||
jdbcValues.finishUp( session );
|
||||
persistenceContext.afterLoad();
|
||||
persistenceContext.initializeNonLazyCollections();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
|
|
Loading…
Reference in New Issue