Skip to content

Commit

Permalink
Use single loader to load single instance on multiloading
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever authored and sebersole committed Dec 15, 2021
1 parent cef98f6 commit 647c2a9
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -234,6 +235,9 @@ private List<T> loadEntitiesById(
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 );
Expand Down Expand Up @@ -333,6 +337,11 @@ public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry e
);
}

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,
Expand Down

0 comments on commit 647c2a9

Please sign in to comment.