diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdLoaderStandard.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdLoaderStandard.java index 20affff47e..ec3cec041f 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdLoaderStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiIdLoaderStandard.java @@ -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 implements MultiIdEntityLoader { 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 implements MultiIdEntityLoader { ); } + private List performSingleMultiLoad(Object id, LockOptions lockOptions, SharedSessionContractImplementor session) { + T loaded = (T) entityDescriptor.load( id, null, lockOptions, session ); + return Collections.singletonList( loaded ); + } + private List performUnorderedMultiLoad( Object[] ids, SharedSessionContractImplementor session,