HHH-12268 : LazyInitializationException thrown from lazy collection when batch fetching enabled and owning entity refreshed with lock

(cherry picked from commit 06c78087ff66f6d2f24408169da5510f2e88a549)
This commit is contained in:
Gail Badner 2020-07-13 13:59:35 -07:00 committed by gbadner
parent f13cdcf2c9
commit b4b5a6f379
3 changed files with 6 additions and 5 deletions

View File

@ -200,6 +200,9 @@ public final List loadEntityBatch(
final QueryParameters qp = new QueryParameters();
qp.setPositionalParameterTypes( types );
qp.setPositionalParameterValues( ids );
qp.setOptionalObject( optionalObject );
qp.setOptionalEntityName( optionalEntityName );
qp.setOptionalId( optionalId );
qp.setLockOptions( lockOptions );
if ( readOnly != null ) {
qp.setReadOnly( readOnly );

View File

@ -16,12 +16,10 @@
import org.hibernate.engine.internal.TwoPhaseLoad;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
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.EventType;
import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PostLoadEventListener;
import org.hibernate.event.spi.PreLoadEvent;
import org.hibernate.event.spi.PreLoadEventListener;
import org.hibernate.internal.CoreLogging;

View File

@ -232,9 +232,9 @@ public void hydrateEntityState(ResultSet resultSet, ResultSetProcessingContextIm
// determine which entity instance to use. Either the supplied one, or instantiate one
Object entityInstance = null;
if ( isReturn &&
context.shouldUseOptionalEntityInformation() &&
context.getQueryParameters().getOptionalObject() != null ) {
// If an "optional" instance with an EntityKey equal to entityKey is available
// in the context, then use that instance.
if ( isReturn && context.getQueryParameters().getOptionalObject() != null ) {
final EntityKey optionalEntityKey = ResultSetProcessorHelper.getOptionalObjectKey(
context.getQueryParameters(),
context.getSession()