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