From a784ca2027b9b79e21082c875ba17fcf99b7977e Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 6 Aug 2024 08:55:04 +0200 Subject: [PATCH] HHH-18439 Account for null values in query cache hit Also, solve an assertion error in query result type check when selecting `null` literals --- .../java/org/hibernate/query/sqm/internal/SqmUtil.java | 7 +++++-- .../sql/results/jdbc/internal/JdbcValuesCacheHit.java | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java index 43d15bef2c..9110f34bdd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmUtil.java @@ -1094,7 +1094,10 @@ public class SqmUtil { } final JavaType selectionExpressibleJavaType = selectionExpressible.getExpressibleJavaType(); - assert selectionExpressibleJavaType != null; + if ( selectionExpressibleJavaType == null ) { + // nothing we can validate + return; + } final Class selectionExpressibleJavaTypeClass = selectionExpressibleJavaType.getJavaTypeClass(); if ( selectionExpressibleJavaTypeClass != Object.class ) { @@ -1103,7 +1106,7 @@ public class SqmUtil { return; } - if ( selectionExpressibleJavaType instanceof PrimitiveJavaType primitiveJavaType ) { + if ( selectionExpressibleJavaType instanceof final PrimitiveJavaType primitiveJavaType ) { if ( primitiveJavaType.getPrimitiveClass() == resultClass ) { return; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesCacheHit.java b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesCacheHit.java index 62662d8f5e..a2902861ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesCacheHit.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/jdbc/internal/JdbcValuesCacheHit.java @@ -176,12 +176,12 @@ public class JdbcValuesCacheHit extends AbstractJdbcValues { if ( valueIndexesToCacheIndexes == null ) { return ( (Object[]) row )[valueIndex]; } - else if ( row.getClass() != Object[].class ) { - assert valueIndexesToCacheIndexes[valueIndex] == 0; - return row; + else if ( row instanceof Object[] ) { + return ( (Object[]) row )[valueIndexesToCacheIndexes[valueIndex]]; } else { - return ( (Object[]) row )[valueIndexesToCacheIndexes[valueIndex]]; + assert valueIndexesToCacheIndexes[valueIndex] == 0; + return row; } }