From fe7d2814e37c673dc1947386c0bcfdcca9af6253 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 13 Sep 2023 17:01:11 +0200 Subject: [PATCH] HHH-17201 Unexpected value type exception for unordered multi id Load with ordered return disable --- .../internal/MultiIdentifierLoadAccessImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/MultiIdentifierLoadAccessImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/MultiIdentifierLoadAccessImpl.java index d7f3845168..7f9ed62e1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/MultiIdentifierLoadAccessImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/MultiIdentifierLoadAccessImpl.java @@ -6,6 +6,7 @@ */ package org.hibernate.internal; +import java.util.Collections; import java.util.List; import java.util.function.Supplier; @@ -15,6 +16,7 @@ import org.hibernate.MultiIdentifierLoadAccess; import org.hibernate.graph.GraphSemantic; import org.hibernate.graph.RootGraph; import org.hibernate.graph.spi.RootGraphImplementor; +import org.hibernate.loader.ast.internal.LoaderHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.loader.ast.spi.MultiIdLoadOptions; @@ -165,6 +167,13 @@ class MultiIdentifierLoadAccessImpl implements MultiIdentifierLoadAccess, @Override @SuppressWarnings( "unchecked" ) public List multiLoad(List ids) { - return perform( () -> (List) entityPersister.multiLoad( ids.toArray( new Object[ 0 ] ), session, this ) ); + if ( ids.isEmpty() ) { + return Collections.emptyList(); + } + return perform( () -> (List) entityPersister.multiLoad( + ids.toArray( LoaderHelper.createTypedArray( ids.get( 0 ).getClass(), ids.size() ) ), + session, + this + ) ); } }