HHH-13932: Check for non existing query parameter in CriteriaQueryTypeQueryAdapter and throw an exception with the corresponding message
This commit is contained in:
parent
3f2a4947a7
commit
f572141ce9
|
@ -370,7 +370,10 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
|
|||
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() ) {
|
||||
|
|
|
@ -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<Item> query = builder.createQuery( Item.class );
|
||||
Root<Item> root = query.from( Item.class );
|
||||
ParameterExpression<String> parameter = builder.parameter( String.class, "name" );
|
||||
Predicate predicate = builder.equal( root.get( "name" ), parameter );
|
||||
query.where( predicate );
|
||||
TypedQuery<Item> criteriaQuery = entityManager.createQuery( query );
|
||||
ParameterExpression<String> nonExistingParam = builder.parameter( String.class, "nonExistingParam" );
|
||||
criteriaQuery.setParameter( nonExistingParam, "George" );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParameterPassingTypeNotFails() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
|
Loading…
Reference in New Issue