{"record":{"id":"f4108d98ab54aa59","repo":"hibernate/hibernate-orm","slug":"could-not-determine-mapping-type-for-ordinal-param","errorCode":null,"errorMessage":"Could not determine mapping type for ordinal parameter '?{}'","messagePattern":"Could not determine mapping type for ordinal parameter '\\?(.+?)'","errorType":"exception","errorClass":"QueryParameterException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java","lineNumber":327,"sourceCode":"\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\n\t\tpublic MutableCacheKeyImpl(int parameterBindingMapSize) {\n\t\t\tvalues = new ArrayList<>( parameterBindingMapSize );\n\t\t}\n\n\t\t@Override","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java#L309-L345","documentation":"The ordinal variant of the type-resolution failure: Hibernate tries to infer the parameter's BasicType from bound values, finds none, and the parameter has no explicit bind type, so QueryParameterException is thrown naming the '?N' label. It happens after binding (values exist but are null) or when the binding carries no type the mapper can use.","triggerScenarios":"setParameter(1, null) with no type argument on an ordinal parameter whose type cannot be determined from the query; native queries binding null ordinals without an explicit type.","commonSituations":"Optional filters using ordinal labels and null defaults; migration from code that relied on the parameter's static type; native SQL with untyped null binds.","solutions":["Bind nulls with an explicit type: setParameter(1, null, Integer.class).","Omit the predicate when the value is null instead of binding null.","For native SQL, cast the null in the query text or register the parameter type on the NativeQuery."],"exampleFix":"// before\nq.setParameter(1, null); // later: could not determine mapping type for '?1'\n\n// after\nq.setParameter(1, null, Integer.class); // explicit type\n// or omit the predicate when the value is null","handlingStrategy":"validation","validationCode":"static void bindNullable(org.hibernate.query.Query<?> q, int position, Object value, Class<?> javaType) {\n    if (value == null) {\n        q.setParameter(position, null, javaType); // explicit type for null\n    } else {\n        q.setParameter(position, value);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the typed setParameter overload when binding null ordinals.","Skip optional predicates rather than binding null placeholders.","For native SQL, prefer named parameters with registered types over untyped nulls."],"tags":["hibernate","positional-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"}