{"record":{"id":"d8025eecacf81dc4","repo":"hibernate/hibernate-orm","slug":"cannot-dereference-an-entity-name-d8025e","errorCode":null,"errorMessage":"Cannot dereference an entity name","messagePattern":"Cannot dereference an entity name","errorType":"exception","errorClass":"HqlInterpretationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmLiteralEntityType.java","lineNumber":89,"sourceCode":"//\tpublic DomainResult createDomainResult(\n//\t\t\tString resultVariable,\n//\t\t\tDomainResultCreationState creationState) {\n//\t\tthrow new SemanticException( \"Selecting an entity type is not allowed. An entity type expression can be used to restrict query polymorphism \");\n//\t\t// todo (6.0) : but could be ^^ - consider adding support for this (returning Class)\n//\t}\n\n\n\t@Override\n\tpublic String asLoggableText() {\n\t\treturn \"TYPE(\" + entityType + \")\";\n\t}\n\n\t@Override\n\tpublic SemanticPathPart resolvePathPart(\n\t\t\tString name,\n\t\t\tboolean isTerminal,\n\t\t\tSqmCreationState creationState) {\n\t\tthrow new HqlInterpretationException( \"Cannot dereference an entity name\" );\n\t}\n\n\t@Override\n\tpublic SqmPath<?> resolveIndexedAccess(\n\t\t\tSqmExpression<?> selector,\n\t\t\tboolean isTerminal,\n\t\t\tSqmCreationState creationState) {\n\t\tthrow new HqlInterpretationException( \"Cannot dereference an entity name\" );\n\t}\n\n\t@Override\n\tpublic void appendHqlString(StringBuilder hql, SqmRenderContext context) {\n\t\thql.append( entityType.getName() );\n\t}\n\n\t@Override\n\tpublic boolean equals(@Nullable Object object) {\n\t\treturn object instanceof SqmLiteralEntityType<?> that","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmLiteralEntityType.java#L71-L107","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add and use an alias: from com.acme.Customer c ... select c.name.","In TYPE() comparisons keep the entity name terminal: type(o) = com.acme.Customer (no trailing path).","Check for a typo'd or missing alias - Hibernate may resolve a stray token as an entity name."],"exampleFix":"-- before\nselect com.acme.Customer.name from Order o join o.customer com.acme.Customer\n\n-- after\nselect c.name from Order o join o.customer c","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery( hql, Tuple.class ).getResultList();\n} catch ( org.hibernate.query.hql.HqlInterpretationException e ) {\n    // an entity name was dereferenced - fix the alias\n    throw new BadRequestException( \"Cannot dereference entity name in query: \" + e.getMessage(), e );\n}","preventionTips":["Always declare and use an identification variable for each entity in HQL.","Keep entity names terminal in type(...) comparisons.","Lint generated HQL for fully-qualified entity names followed by a dot."],"tags":["hibernate","hql","entity","path-resolution","sqm"],"backgroundTag":"invalid-query-path","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}