hibernate/hibernate-orm · error · ParameterLabelException

Unlabeled ordinal parameter ('?' rather than ?1)

Error message

Unlabeled ordinal parameter ('?' rather than ?1)

What it means

Thrown by SemanticQueryBuilder.visitPositionalParameter as a ParameterLabelException when a positional parameter is written as a bare '?' without its numeric label. Hibernate requires explicitly labeled positional parameters ('?1') — JPA does not support unlabeled ones — so the unlabeled parameter in the HQL text is rejected at translation time.

Solutions

  1. Ordinal parameters must be labelled starting from ?1; a bare '?' is not allowed here. Replace '?' with an explicitly numbered parameter such as ?1, or use a named parameter.
Defensive patterns

Strategy: validation

When it happens

Trigger: A bare '?' placeholder is used instead of a labelled ordinal parameter: Unlabeled ordinal parameter ('?' rather than ?1)

Common situations: HQL queries written with unlabelled '?' placeholders; Hibernate requires '?1', '?2', ... labels.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:4514

				new SqmNamedParameter<>(
						ctx.getChild( 1 ).getText(),
						parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
						expressibleType,
						nodeBuilder()
				)
		);
	}

	@Override
	public SqmPositionalParameter<?> visitPositionalParameter(HqlParser.PositionalParameterContext ctx) {
		return visitPositionalParameter( ctx, null );
	}

	private <T> SqmPositionalParameter<T> visitPositionalParameter(
			HqlParser.PositionalParameterContext ctx,
			SqmBindableType<T> expressibleType) {
		if ( ctx.getChildCount() == 1 ) {
			throw new ParameterLabelException( "Unlabeled ordinal parameter ('?' rather than ?1)" );
		}
		parameterStyle = parameterStyle.withPositional();
		return resolveParameter(
				new SqmPositionalParameter<>(
						Integer.parseInt( ctx.getChild( 1 ).getText() ),
						parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
						expressibleType,
						nodeBuilder()
				)
		);
	}

	private <T extends AbstractSqmParameter<?>> T resolveParameter(T parameter) {
		if ( parameters == null ) {
			parameters = new HashMap<>();
		}
		final Object key = parameter.getName() == null ? parameter.getPosition() : parameter.getName();
		final var existingParameter = parameters.putIfAbsent( key, parameter );

View on GitHub (pinned to fad1729dce)