diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/TupleImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/TupleImpl.java index d8c3f7decb..ee404d2bba 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/TupleImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/TupleImpl.java @@ -9,6 +9,7 @@ package org.hibernate.sql.results.internal; import java.util.List; import jakarta.persistence.TupleElement; +import org.hibernate.internal.util.type.PrimitiveWrapperHelper; import org.hibernate.query.JpaTuple; /** @@ -43,7 +44,7 @@ public class TupleImpl implements JpaTuple { public X get(String alias, Class type) { final Object untyped = get( alias ); if ( untyped != null ) { - if ( !type.isInstance( untyped ) ) { + if (!elementTypeMatches(type, untyped)) { throw new IllegalArgumentException( String.format( "Requested tuple value [alias=%s, value=%s] cannot be assigned to requested type [%s]", @@ -73,7 +74,7 @@ public class TupleImpl implements JpaTuple { @SuppressWarnings("unchecked") public X get(int i, Class type) { final Object result = get( i ); - if ( result != null && !type.isInstance( result ) ) { + if ( result != null && !elementTypeMatches( type, result ) ) { throw new IllegalArgumentException( String.format( "Requested tuple value [index=%s, realType=%s] cannot be assigned to requested type [%s]", @@ -96,6 +97,12 @@ public class TupleImpl implements JpaTuple { return row[i]; } + private boolean elementTypeMatches(Class type, Object untyped) { + return type.isInstance(untyped) + || type.isPrimitive() + && PrimitiveWrapperHelper.getDescriptorByPrimitiveType( type).getWrapperClass().isInstance( untyped); + } + @Override public Object[] toArray() { return row;