1212import org .hibernate .metamodel .mapping .BasicValuedMapping ;
1313import org .hibernate .metamodel .mapping .MappingModelExpressible ;
1414import org .hibernate .metamodel .mapping .ModelPart ;
15+ import org .hibernate .query .QueryArgumentException ;
1516import org .hibernate .type .BindableType ;
1617import org .hibernate .query .QueryParameter ;
1718import org .hibernate .query .spi .QueryParameterBinding ;
@@ -130,10 +131,12 @@ public void setBindValue(Object value, boolean resolveJdbcTypeIfNecessary) {
130131}
131132
132133@ Override
133- public void setBindValue (Object value , @ Nullable BindableType <T > clarifiedType ) {
134+ public void setBindValue (Object value , @ Nullable BindableType <? > clarifiedType ) {
134135if ( !handleAsMultiValue ( value , clarifiedType ) ) {
135136if ( clarifiedType != null ) {
136- bindType = clarifiedType ;
137+ // UNSOUND!!!
138+ // We should be creating a whole new object
139+ bindType = (BindableType <T >) clarifiedType ;
137140}
138141
139142final Object coerced = coerce ( value );
@@ -178,7 +181,7 @@ private void bindNull(boolean resolveJdbcTypeIfNecessary) {
178181}
179182}
180183
181- private boolean handleAsMultiValue (Object value , @ Nullable BindableType <T > bindableType ) {
184+ private boolean handleAsMultiValue (Object value , @ Nullable BindableType <? > bindableType ) {
182185if ( queryParameter .allowsMultiValuedBinding ()
183186&& value instanceof Collection
184187&& !( bindableType == null
@@ -242,9 +245,10 @@ public void setBindValues(Collection<?> values) {
242245}
243246
244247@ Override
245- public void setBindValues (Collection <?> values , BindableType <T > clarifiedType ) {
248+ public void setBindValues (Collection <?> values , BindableType <? > clarifiedType ) {
246249if ( clarifiedType != null ) {
247- bindType = clarifiedType ;
250+ // UNSOUND
251+ bindType = (BindableType <T >) clarifiedType ;
248252}
249253setBindValues ( values );
250254}
@@ -265,7 +269,7 @@ private void setExplicitTemporalPrecision(@SuppressWarnings("deprecation") Tempo
265269}
266270}
267271
268- private JavaType <? super T > determineJavaType (BindableType <? super T > bindType ) {
272+ private JavaType <T > determineJavaType (BindableType <T > bindType ) {
269273return getCriteriaBuilder ().resolveExpressible ( bindType ).getExpressibleJavaType ();
270274}
271275
@@ -320,14 +324,8 @@ else if ( canValueBeCoerced( queryParameter.getHibernateType() ) ) {
320324}
321325}
322326catch (HibernateException ex ) {
323- throw new IllegalArgumentException (
324- String .format (
325- "Parameter value [%s] did not match expected type [%s]" ,
326- value ,
327- bindType
328- ),
329- ex
330- );
327+ throw new QueryArgumentException ( "Argument to query parameter has an incompatible type: " + ex .getMessage (),
328+ queryParameter .getParameterType (), value );
331329}
332330}
333331
0 commit comments