hibernate/hibernate-orm · error · QueryParameterException

No argument for named parameter ':{}'

Error message

No argument for named parameter ':{}'

What it means

Before a query executes, QueryParameterBindingsImpl.validate() walks every declared parameter and throws QueryParameterException naming the first unbound one. Hibernate does not substitute null or ignore missing named arguments, so every :name in the HQL must receive a setParameter call before list()/getResultList()/executeUpdate().

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java:172

	}

	@Override
	public QueryParameterBinding<?> getBinding(String name) {
		final var binding = parameterBindingMapByNameOrPosition.get( name );
		if ( binding == null ) {
			// Invoke this method to throw the exception
			parameterMetadata.getQueryParameter( name );
		}
		return binding;
	}

	@Override
	public void validate() {
		for ( var entry : parameterBindingMap.entrySet() ) {
			if ( !entry.getValue().isBound() ) {
				final var queryParameter = entry.getKey();
				if ( queryParameter.isNamed() ) {
					throw new QueryParameterException(
							"No argument for named parameter ':"
								+ queryParameter.getName() + "'" );
				}
				else {
					throw new QueryParameterException(
							"No argument for ordinal parameter '?"
								+ queryParameter.getPosition() + "'" );
				}
			}
		}
	}

	@Override
	public boolean hasAnyMultiValuedBindings() {
		for ( var binding : parameterBindingMap.values() ) {
			if ( binding.isMultiValued() ) {
				return true;
			}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Set every declared parameter before execution; the message names the missing one.
  2. Build the predicate and its binding in the same conditional block so they cannot diverge.
  3. For genuinely optional filters, omit the whole predicate when the value is absent (dynamic query building or Criteria with optional predicates).

Example fix

// before
var q = session.createQuery("from Person p where p.status = :status", Person.class);
// setParameter forgotten
q.list(); // throws: No argument for named parameter ':status'

// after
q.setParameter("status", status != null ? status : Status.ACTIVE);
// or: append "and p.status = :status" to the HQL only when you also bind it
Defensive patterns

Strategy: validation

Validate before calling

static void assertAllBound(org.hibernate.query.Query<?> q, java.util.Set<String> boundNames) {
    for (String name : q.getParameterMetadata().getNamedParameterNames()) {
        if (!boundNames.contains(name))
            throw new IllegalArgumentException("Unbound parameter :" + name);
    }
}

Try / catch

try {
    return q.list();
} catch (org.hibernate.QueryParameterException e) {
    // message names the missing ':name'; log and surface as a 400
}

Prevention

When it happens

Trigger: createQuery("... where p.status = :status") executed without any setParameter("status", ...); a dynamic filter builder that appends the predicate but skips the binding on some branch, or binds after a conditional early return.

Common situations: Optional search filters where one code path forgets the bind; refactors that rename a parameter only in the HQL; new parameters added to a shared query string without updating all call sites.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/923c170783afea2e. Report an issue: GitHub.