Fix CoercionException conversion to IllegalArgumentException for Query parameter binding

This commit is contained in:
Andrea Boriero 2021-09-30 19:30:55 +02:00 committed by Christian Beikov
parent 8df7a3ab16
commit b872d8ad74
1 changed files with 16 additions and 4 deletions

View File

@ -105,11 +105,23 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
}
if ( ! getTypeConfiguration().getSessionFactory().getJpaMetamodel().getJpaCompliance().isLoadByIdComplianceEnabled() ) {
if ( bindType != null ) {
value = bindType.getExpressableJavaTypeDescriptor().coerce( value, this );
try {
if ( bindType != null ) {
value = bindType.getExpressableJavaTypeDescriptor().coerce( value, this );
}
else if ( queryParameter.getHibernateType() != null ) {
value = queryParameter.getHibernateType().getExpressableJavaTypeDescriptor().coerce( value, this );
}
}
else if ( queryParameter.getHibernateType() != null ) {
value = queryParameter.getHibernateType().getExpressableJavaTypeDescriptor().coerce( value, this );
catch (CoercionException ce) {
throw new IllegalArgumentException(
String.format(
"Parameter value [%s] did not match expected type [%s ]",
value,
bindType.getTypeName()
),
ce
);
}
}