Use single loader to load single instance on multiloading

This commit is contained in:
Fabio Massimo Ercoli 2021-12-14 20:24:18 +01:00 committed by Steve Ebersole
parent cef98f67a9
commit 647c2a923c
1 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@ package org.hibernate.loader.ast.internal;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.hibernate.LockMode;
@ -234,6 +235,9 @@ public class MultiIdLoaderStandard<T> implements MultiIdEntityLoader<T> {
assert ! idsInBatch.isEmpty();
final int numberOfIdsInBatch = idsInBatch.size();
if ( numberOfIdsInBatch == 1 ) {
return performSingleMultiLoad( idsInBatch.get( 0 ), lockOptions, session );
}
if ( log.isTraceEnabled() ) {
log.tracef( "#loadEntitiesById(`%s`, `%s`, ..)", entityDescriptor.getEntityName(), numberOfIdsInBatch );
@ -333,6 +337,11 @@ public class MultiIdLoaderStandard<T> implements MultiIdEntityLoader<T> {
);
}
private List<T> performSingleMultiLoad(Object id, LockOptions lockOptions, SharedSessionContractImplementor session) {
T loaded = (T) entityDescriptor.load( id, null, lockOptions, session );
return Collections.singletonList( loaded );
}
private List<T> performUnorderedMultiLoad(
Object[] ids,
SharedSessionContractImplementor session,