hibernate/hibernate-orm · error · HqlInterpretationException

Cannot dereference an entity name

Error message

Cannot dereference an entity name

What it means

SqmLiteralEntityType is the SQM node Hibernate creates when a path segment resolves to an entity name (typically a fully-qualified entity class name used as a literal, as in type() comparisons or treat targets). An entity name cannot be navigated like a root or alias, so resolvePathPart throws HqlInterpretationException('Cannot dereference an entity name').

Source

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

//	public DomainResult createDomainResult(
//			String resultVariable,
//			DomainResultCreationState creationState) {
//		throw new SemanticException( "Selecting an entity type is not allowed. An entity type expression can be used to restrict query polymorphism ");
//		// todo (6.0) : but could be ^^ - consider adding support for this (returning Class)
//	}


	@Override
	public String asLoggableText() {
		return "TYPE(" + entityType + ")";
	}

	@Override
	public SemanticPathPart resolvePathPart(
			String name,
			boolean isTerminal,
			SqmCreationState creationState) {
		throw new HqlInterpretationException( "Cannot dereference an entity name" );
	}

	@Override
	public SqmPath<?> resolveIndexedAccess(
			SqmExpression<?> selector,
			boolean isTerminal,
			SqmCreationState creationState) {
		throw new HqlInterpretationException( "Cannot dereference an entity name" );
	}

	@Override
	public void appendHqlString(StringBuilder hql, SqmRenderContext context) {
		hql.append( entityType.getName() );
	}

	@Override
	public boolean equals(@Nullable Object object) {
		return object instanceof SqmLiteralEntityType<?> that

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add and use an alias: from com.acme.Customer c ... select c.name.
  2. In TYPE() comparisons keep the entity name terminal: type(o) = com.acme.Customer (no trailing path).
  3. Check for a typo'd or missing alias - Hibernate may resolve a stray token as an entity name.

Example fix

-- before
select com.acme.Customer.name from Order o join o.customer com.acme.Customer

-- after
select c.name from Order o join o.customer c
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return session.createQuery( hql, Tuple.class ).getResultList();
} catch ( org.hibernate.query.hql.HqlInterpretationException e ) {
    // an entity name was dereferenced - fix the alias
    throw new BadRequestException( "Cannot dereference entity name in query: " + e.getMessage(), e );
}

Prevention

When it happens

Trigger: HQL that continues a path after an entity name: select com.acme.Customer.name from ..., where com.acme.Customer.id = ..., or criteria code calling resolvePathPart on an SqmLiteralEntityType node.

Common situations: Missing identification variable/alias in the query; Java-style static navigation copied into HQL; query generators emitting fully-qualified names instead of aliases; confusing the entity name inside TYPE(...) with a path root.

Related errors


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