hibernate/hibernate-orm · error · UnknownPathException

Static field reference [%s#%s] cannot be de-referenced

Error message

Static field reference [%s#%s] cannot be de-referenced

What it means

SqmFieldLiteral is the SQM node Hibernate creates when a path resolves to a static field of a class (e.g. com.acme.Consts.MAX in HQL). It is a terminal node: resolvePathPart rejects any further dot-navigation with UnknownPathException, naming the owning Java type and the field, because a static field reference has no members to dereference.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmFieldLiteral.java:117

		return getJavaTypeDescriptor().getJavaTypeClass();
	}

	@Override
	public <X> X accept(SemanticQueryWalker<X> walker) {
		return walker.visitFieldLiteral( this );
	}

	@Override
	public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
		SqmLiteral.appendHqlString( hql, getJavaTypeDescriptor(), getValue() );
	}

	@Override
	public SemanticPathPart resolvePathPart(
			String name,
			boolean isTerminal,
			SqmCreationState creationState) {
		throw new UnknownPathException(
				String.format(
						Locale.ROOT,
						"Static field reference [%s#%s] cannot be de-referenced",
						fieldJavaType.getTypeName(),
						fieldName
				)
		);
	}

	@Override
	public SqmPath<?> resolveIndexedAccess(
			SqmExpression<?> selector,
			boolean isTerminal,
			SqmCreationState creationState) {
		throw new UnknownPathException(
				String.format(
						Locale.ROOT,
						"Static field reference [%s#%s] cannot be de-referenced",

View on GitHub (pinned to fad1729dce)

Solutions

  1. End the path at the static field and compare against it directly, or reference the deeper constant by its own fully-qualified name.
  2. Bind values you cannot reference directly as query parameters instead of navigating static structures in HQL.
  3. Fix the path so every segment after the class name is a real field and the static field is the last segment.

Example fix

-- before
select o from Order o where o.mask = com.acme.Flags.ALL.mask  -- .mask dereferences a static field

-- after
select o from Order o where o.mask = :mask  -- bind com.acme.Flags.ALL.mask in Java
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return session.createQuery( hql, Tuple.class ).getResultList();
} catch ( org.hibernate.query.sqm.UnknownPathException e ) {
    // a static-field path was dereferenced - surface the offending type#field
    throw new BadRequestException( "Invalid path in query: " + e.getMessage(), e );
}

Prevention

When it happens

Trigger: HQL paths that continue past a static field: where o.mask = com.acme.Flags.ALL.mask, select com.acme.Consts.DEFAULT.name, or any path where an intermediate segment resolved to a static field but more segments follow; also criteria code calling resolvePathPart on an SqmFieldLiteral node.

Common situations: Chaining Java-style constant paths (Consts.SETTINGS.TIMEOUT) inside HQL; typos in fully-qualified names that make Hibernate resolve an intermediate segment as a static field; generated queries that concatenate constant prefixes with dynamic suffixes.

Related errors


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