{"record":{"id":"a05e2af46b374529","repo":"hibernate/hibernate-orm","slug":"typedparametervalue-has-no-type","errorCode":null,"errorMessage":"TypedParameterValue has no type","messagePattern":"TypedParameterValue has no type","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/AbstractCommonQueryContract.java","lineNumber":1285,"sourceCode":"\t@Nonnull\n\tpublic <P> CommonQueryContractImplementor setParameter(\n\t\t\t@Nonnull QueryParameter<P> parameter,\n\t\t\t@Nullable P value,\n\t\t\t@Nonnull Type<P> type) {\n\t\tlocateBinding( parameter ).setBindValue( value, (BindableType<P>) type );\n\t\treturn this;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <P> CommonQueryContractImplementor setParameter(\n\t\t\t@Nonnull Parameter<P> parameter,\n\t\t\t@Nullable P value) {\n\t\tif ( value instanceof TypedParameterValue<?> typedParameterValue ) {\n\t\t\tfinal var parameterType = parameter.getParameterType();\n\t\t\tfinal var type = typedParameterValue.type();\n\t\t\tif ( type == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"TypedParameterValue has no type\" );\n\t\t\t}\n\t\t\tif ( !parameterType.isAssignableFrom( type.getJavaType() ) ) {\n\t\t\t\tthrow new QueryArgumentException( \"Given TypedParameterValue is not assignable to given Parameter type\",\n\t\t\t\t\t\tparameterType, typedParameterValue.value() );\n\t\t\t}\n\t\t\t@SuppressWarnings(\"unchecked\") // safe, because we just checked\n\t\t\tfinal var typedValue = (TypedParameterValue<P>) value;\n\t\t\tfinal var castValue = typedValue.value();\n\t\t\tfinal var castType = typedValue.type();\n\t\t\tif ( parameter instanceof QueryParameter<P> queryParameter ) {\n\t\t\t\tsetParameter( queryParameter, castValue, castType );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlocateBinding( parameter ).setBindValue( castValue, castType );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tlocateBinding( parameter ).setBindValue( value, resolveJdbcParameterTypeIfNecessary() );","sourceCodeStart":1267,"sourceCodeEnd":1303,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractCommonQueryContract.java#L1267-L1303","documentation":"Thrown by setParameter(Parameter<P>, P value) when value is a TypedParameterValue whose type() returns null. TypedParameterValue pairs a value with its Hibernate Type for explicit bind typing; when constructed as new TypedParameterValue<>(null, v) the pair carries no type information, and Hibernate refuses to bind it rather than guessing.","triggerScenarios":"new TypedParameterValue<>(null, \"abc\") passed to query.setParameter(param, typedValue). A factory/mapper building TypedParameterValue with an Optional<Type> that is empty; copy-paste from setParameter(name, value) paths where the untyped overload is legal (plain values don't need a type).","commonSituations":"Code intended for setParameter(String,Object) — which handles raw values — refactored onto the Parameter-typed overload; conditional typing logic ('use Long type only for longs, else null') leaving null in the non-long branch.","solutions":["Always supply a type: new TypedParameterValue<>(StandardBasicTypes.STRING, \"abc\") or a JavaType/BasicTypeReference","If you don't need explicit typing, pass the raw value instead of a TypedParameterValue","Centralize TypedParameterValue construction in one factory method that throws a clear error if the type argument is null"],"exampleFix":"// before\nquery.setParameter( param, new TypedParameterValue<>( null, 42 ) );\n\n// after\nquery.setParameter( param, new TypedParameterValue<>( StandardBasicTypes.INTEGER, 42 ) );\n// or simply the raw value:\nquery.setParameter( param, 42 );","handlingStrategy":"type-guard","validationCode":"TypedParameterValue<?> tpv = (TypedParameterValue<?>) value;\nif ( tpv.type() == null ) throw new IllegalArgumentException( \"TypedParameterValue needs a type\" );\nquery.setParameter( param, tpv );","typeGuard":"static boolean isFullyTyped(TypedParameterValue<?> v) {\n    return v != null && v.type() != null;\n}","tryCatchPattern":null,"preventionTips":["Construct TypedParameterValue only via one factory that requires a non-null BasicTypeReference","Skip the wrapper entirely when explicit typing isn't needed","Forbid 'new TypedParameterValue(' outside the factory in code review"],"tags":["hibernate","query-parameters","typed-parameter-value","null-safety"],"backgroundTag":"typed-parameter-value-missing-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}