hibernate/hibernate-orm · error · FunctionArgumentException

Argument ' ' of 'version()' does not resolve to an entity…

Error message

Argument '{}' of 'version()' does not resolve to an entity type

What it means

Thrown by SemanticQueryBuilder.handleVersionPath when the argument of 'version()' does not resolve to an entity type at all. 'version()' is only defined for entities with optimistic-lock version attributes, so any non-entity argument path raises a FunctionArgumentException naming the offending path.

Solutions

  1. Pass an entity type (entity name or entity-valued path) as the argument to version(); the argument currently resolves to a non-entity expression. Check that the path used in version(...) refers to a mapped entity.
Defensive patterns

Strategy: validation

When it happens

Trigger: A name/path expected to denote an entity type does not: Argument '<value>' of 'version()' does not resolve to an entity type

Common situations: Passing non-entity arguments to version()/naturalid(), or a TREAT target / entity name that is not a mapped entity; commonly a typo or unmapped class.


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

Appendix: source

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

	public SqmPath<?> visitEntityVersionReference(HqlParser.EntityVersionReferenceContext ctx) {
		return handleVersionPath( consumeDomainPath( ctx.path() ) );
	}

	@Nonnull
	private static <U> SqmPath<?> handleVersionPath(SqmPath<U> sqmPath) {
		if ( sqmPath.getReferencedPathSource().getPathType()
				instanceof AbstractIdentifiableType<U> identifiableType ) {
			if ( !identifiableType.hasVersionAttribute() ) {
				throw new FunctionArgumentException( "Argument '" + sqmPath.getNavigablePath()
							+ "' of 'version()' is a '" + identifiableType.getTypeName()
							+ "' and does not have a '@Version' attribute" );
			}
			final var versionAttribute = identifiableType.findVersionAttribute();
			assert versionAttribute != null; // Safe, we just checked hasVersionAttribute()
			return sqmPath.get( versionAttribute );
		}
		else {
			throw new FunctionArgumentException( "Argument '" + sqmPath.getNavigablePath()
						+ "' of 'version()' does not resolve to an entity type" );
		}
	}

	@Override
	public SqmPath<?> visitEntityNaturalIdExpression(HqlParser.EntityNaturalIdExpressionContext ctx) {
		return visitEntityNaturalIdReference( ctx.entityNaturalIdReference() );
	}

	@Override
	public SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferenceContext ctx) {
		if ( ctx.pathContinuation() != null ) {
			throw new UnsupportedOperationException( "Path continuation from 'naturalid()' reference not yet implemented" );
		}
		return handleNaturalIdPath( consumeDomainPath( ctx.path() ) );
	}

	private static <U> SqmPath<?> handleNaturalIdPath(SqmPath<U> sqmPath) {

View on GitHub (pinned to fad1729dce)