From f572141ce9bee9b504f31c0d5a6b6d0e5d6c76a1 Mon Sep 17 00:00:00 2001 From: Katiforis Date: Sat, 18 Apr 2020 21:02:29 +0300 Subject: [PATCH] HHH-13932: Check for non existing query parameter in CriteriaQueryTypeQueryAdapter and throw an exception with the corresponding message --- .../compile/CriteriaQueryTypeQueryAdapter.java | 5 ++++- .../CriteriaQueryTypeQueryAdapterTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaQueryTypeQueryAdapter.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaQueryTypeQueryAdapter.java index cab7a67573..057969bfc5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaQueryTypeQueryAdapter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaQueryTypeQueryAdapter.java @@ -370,7 +370,10 @@ public class CriteriaQueryTypeQueryAdapter implements QueryImplementor { return (ExplicitParameterInfo) param; } else if ( ParameterExpression.class.isInstance( param ) ) { - return explicitParameterInfoMap.get( param ); + ExplicitParameterInfo parameterInfo = explicitParameterInfoMap.get( param ); + if ( parameterInfo != null ) { + return parameterInfo; + } } else { for ( ExplicitParameterInfo parameterInfo : explicitParameterInfoMap.values() ) { diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/CriteriaQueryTypeQueryAdapterTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/CriteriaQueryTypeQueryAdapterTest.java index ce0be39508..499c2b69c4 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/CriteriaQueryTypeQueryAdapterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/CriteriaQueryTypeQueryAdapterTest.java @@ -113,6 +113,22 @@ public class CriteriaQueryTypeQueryAdapterTest extends BaseEntityManagerFunction } ); } + @Test(expected = IllegalArgumentException.class) + @TestForIssue(jiraKey = "HHH-13932") + public void testCriteriaQuerySetNonExistingParameter() { + doInJPA( this::entityManagerFactory, entityManager -> { + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery( Item.class ); + Root root = query.from( Item.class ); + ParameterExpression parameter = builder.parameter( String.class, "name" ); + Predicate predicate = builder.equal( root.get( "name" ), parameter ); + query.where( predicate ); + TypedQuery criteriaQuery = entityManager.createQuery( query ); + ParameterExpression nonExistingParam = builder.parameter( String.class, "nonExistingParam" ); + criteriaQuery.setParameter( nonExistingParam, "George" ); + } ); + } + @Test public void testSetParameterPassingTypeNotFails() { doInJPA( this::entityManagerFactory, entityManager -> {