{"record":{"id":"c2ee4f5340944256","repo":"hibernate/hibernate-orm","slug":"no-argument-for-ordinal-parameter","errorCode":null,"errorMessage":"No argument for ordinal parameter '?{}'","messagePattern":"No argument for ordinal parameter '\\?(.+?)'","errorType":"exception","errorClass":"QueryParameterException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java","lineNumber":177,"sourceCode":"\t\tif ( binding == null ) {\n\t\t\t// Invoke this method to throw the exception\n\t\t\tparameterMetadata.getQueryParameter( name );\n\t\t}\n\t\treturn binding;\n\t}\n\n\t@Override\n\tpublic void validate() {\n\t\tfor ( var entry : parameterBindingMap.entrySet() ) {\n\t\t\tif ( !entry.getValue().isBound() ) {\n\t\t\t\tfinal var queryParameter = entry.getKey();\n\t\t\t\tif ( queryParameter.isNamed() ) {\n\t\t\t\t\tthrow new QueryParameterException(\n\t\t\t\t\t\t\t\"No argument for named parameter ':\"\n\t\t\t\t\t\t\t\t+ queryParameter.getName() + \"'\" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new QueryParameterException(\n\t\t\t\t\t\t\t\"No argument for ordinal parameter '?\"\n\t\t\t\t\t\t\t\t+ queryParameter.getPosition() + \"'\" );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean hasAnyMultiValuedBindings() {\n\t\tfor ( var binding : parameterBindingMap.values() ) {\n\t\t\tif ( binding.isMultiValued() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t@Override","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java#L159-L195","documentation":"The ordinal variant of the pre-execution check: QueryParameterBindingsImpl.validate() finds an unbound ordinal parameter and throws QueryParameterException naming its '?N' label. Every ordinal label the query declares must have a corresponding setParameter(N, ...) before the query runs.","triggerScenarios":"A query like \"... where a = ?1 and b = ?2\" executed with only setParameter(1, ...); adding a second condition to the HQL while the call site still binds just one; conditional binds guarded by the wrong flag.","commonSituations":"Extending a query with a new filter but missing one call site; refactors that reorder or add ?N parameters; copy-paste of binding blocks that bind fewer parameters than the query declares.","solutions":["Add the missing setParameter(N, value) for the label named in the message.","When adding a parameter to shared HQL, update every call site (the compiler will not catch it).","Consider named parameters plus a small builder that binds predicate and value together."],"exampleFix":"// before\nvar q = session.createQuery(\"from Person p where p.name = ?1 and p.age > ?2\", Person.class);\nq.setParameter(1, \"Alice\");\nq.list(); // throws: No argument for ordinal parameter '?2'\n\n// after\nq.setParameter(1, \"Alice\");\nq.setParameter(2, 18);","handlingStrategy":"validation","validationCode":"static void assertAllBound(org.hibernate.query.Query<?> q, java.util.Set<Integer> boundPositions) {\n    for (Integer label : q.getParameterMetadata().getOrdinalParameterLabels()) {\n        if (!boundPositions.contains(label))\n            throw new IllegalArgumentException(\"Unbound parameter ?\" + label);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return q.list();\n} catch (org.hibernate.QueryParameterException e) {\n    // message names the missing '?N'; fix the call site binding\n}","preventionTips":["Bind ordinal parameters in one loop over an ordered value list.","Update every call site when adding a ?N predicate to shared HQL.","Prefer named parameters so call sites cannot get out of sync."],"tags":["hibernate","hql","positional-parameters","unbound-parameter","validation"],"backgroundTag":"missing-query-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}