{"record":{"id":"cb220e34b2000fb1","repo":"hibernate/hibernate-orm","slug":"could-not-determine-mapping-type-for-named-paramet","errorCode":null,"errorMessage":"Could not determine mapping type for named parameter ':{}'","messagePattern":"Could not determine mapping type for named parameter ':(.+?)'","errorType":"exception","errorClass":"QueryParameterException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java","lineNumber":322,"sourceCode":"\t\t\t\t// avoid dynamic models\n\t\t\t\treturn typeConfiguration.getBasicTypeForJavaType( javaTypeClass );\n\t\t\t}\n\t\t}\n\n\t\tif ( binding.isMultiValued() ) {\n\t\t\tfinal var iterator = binding.getBindValues().iterator();\n\t\t\tfinal Object firstNonNullBindValue = iterator.hasNext() ? iterator.next() : null;\n\t\t\tif ( firstNonNullBindValue != null ) {\n\t\t\t\treturn typeConfiguration.getBasicTypeForJavaType( firstNonNullBindValue.getClass() );\n\t\t\t}\n\t\t}\n\t\telse if ( binding.getBindValue() != null ) {\n\t\t\treturn typeConfiguration.getBasicTypeForJavaType( binding.getBindValue().getClass() );\n\t\t}\n\n\t\tif ( bindType == null ) {\n\t\t\tif ( queryParameter.isNamed() ) {\n\t\t\t\tthrow new QueryParameterException(\n\t\t\t\t\t\t\"Could not determine mapping type for named parameter ':\"\n\t\t\t\t\t\t\t+ queryParameter.getName() + \"'\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new QueryParameterException(\n\t\t\t\t\t\t\"Could not determine mapping type for ordinal parameter '?\"\n\t\t\t\t\t\t\t+ queryParameter.getPosition() + \"'\" );\n\t\t\t}\n\t\t}\n\n\t\treturn typeConfiguration.getBasicTypeForJavaType( bindType.getJavaType() );\n\t}\n\n\tprivate static class MutableCacheKeyImpl implements MutableCacheKeyBuilder {\n\n\t\tfinal List<Object> values;\n\t\tint hashCode;\n","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java#L304-L340","documentation":"When Hibernate needs the mapping type of a parameter (to prepare the JDBC statement or build a cache key), it first infers a BasicType from any non-null bound value. If the parameter has no usable value and no explicit bind type, the type is undeterminable and Hibernate throws QueryParameterException naming the parameter. This differs from the 'no argument' check: the parameter is bound, but bound uselessly (null, untyped).","triggerScenarios":"setParameter(\"status\", null) without a type hint on a parameter whose type Hibernate cannot resolve statically (common in native queries or parameters used only in expressions with no inferable type); binding only null values so the value-based inference has nothing to work with.","commonSituations":"Optional filters bound as null 'to be safe'; queries migrated after a value/type was removed; native SQL where parameter types are never inferable from the string alone.","solutions":["Use a typed overload for null: setParameter(\"x\", null, String.class) (Hibernate Query) so bindType is set.","Or omit the predicate entirely when the value is null, via dynamic query building.","For native queries, bind with an explicit type or cast in SQL (e.g. cast(null as integer))."],"exampleFix":"// before\nq.setParameter(\"status\", null); // later: could not determine mapping type\n\n// after\nq.setParameter(\"status\", null, String.class); // explicit type\n// or: skip the \"and p.status = :status\" predicate when status == null","handlingStrategy":"validation","validationCode":"static void bindNullable(org.hibernate.query.Query<?> q, String name, Object value, Class<?> javaType) {\n    if (value == null) {\n        q.setParameter(name, null, javaType); // explicit type for null\n    } else {\n        q.setParameter(name, value);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the typed setParameter overload when binding null.","Omit optional predicates instead of binding null placeholders.","In native queries, cast nulls explicitly in SQL or register parameter types."],"tags":["hibernate","named-parameters","null-binding","type-resolution","native-query"],"backgroundTag":"missing-parameter-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}