hibernate/hibernate-orm · error · UnknownPathException
Static enum reference [%s#%s] cannot be de-referenced
Error message
Static enum reference [%s#%s] cannot be de-referenced
What it means
An enum literal in HQL ('MyEnum.CONSTANT') compiles to SqmEnumLiteral, a leaf node holding the enum value and its descriptor. Enum literals expose no navigable members, so attribute navigation off the literal — resolvePathPart — throws UnknownPathException('Static enum reference [FQN#CONSTANT] cannot be de-referenced').
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmEnumLiteral.java:110
public EnumJavaType<E> getExpressibleJavaType() {
return referencedEnumTypeDescriptor;
}
@Override
public Class<E> getJavaType() {
return referencedEnumTypeDescriptor.getJavaTypeClass();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SemanticPathPart
@Override
public SemanticPathPart resolvePathPart(
String name,
boolean isTerminal,
SqmCreationState creationState) {
throw new UnknownPathException(
String.format(
Locale.ROOT,
"Static enum reference [%s#%s] cannot be de-referenced",
referencedEnumTypeDescriptor.getTypeName(),
enumValueName
)
);
}
@Override
public SqmPath<?> resolveIndexedAccess(
SqmExpression<?> selector,
boolean isTerminal,
SqmCreationState creationState) {
throw new UnknownPathException(
String.format(
Locale.ROOT,
"Static enum reference [%s#%s] cannot be de-referenced",View on GitHub (pinned to fad1729dce)
Solutions
- Bind the derived value as a parameter: 'where o.code = :code' with query.setParameter("code", Status.APPROVED.getCode()).
- Compare against the enum itself: 'where o.status = Status.APPROVED' (with @Enumerated mapping).
- If the enum field is mapped on the entity, filter on the entity attribute, not on the literal.
- For code/label tables, join the lookup table instead of dereferencing the enum literal.
Example fix
-- before (HQL)
from Order o where o.statusCode = StatusCode.APPROVED.code
-- after
from Order o where o.statusCode = :code
// Java: query.setParameter("code", StatusCode.APPROVED.getCode()) Defensive patterns
Strategy: try-catch
Validate before calling
// Lint HQL: enum constant followed by another member (Enum.CONSTANT.member) is invalid
static boolean hqlDereferencesEnumLiteral(String hql) {
return hql.matches("(?s).*\\b[A-Z]\\w*\\.[A-Z][A-Z0-9_]*\\.[a-zA-Z]\\w*.*");
} Try / catch
try {
return em.createQuery(hql, resultClass);
} catch (UnknownPathException badPath) { // org.hibernate.query.UnknownPathException
throw new IllegalArgumentException("Enum literal dereferenced in query: " + hql, badPath);
} Prevention
- Bind enum-derived values (code, label) as typed query parameters instead of navigating off literals.
- Compare against the enum constant itself when the attribute is enum-mapped.
- Fail fast: createQuery() all HQL in tests so dereference errors surface in CI.
When it happens
Trigger: HQL like 'where o.code = Status.APPROVED.code' or 'select Status.APPROVED.label from Order o' — any dot-navigation off an enum constant; also 'on' clauses and order-by fragments appending members to enum literals.
Common situations: Enums carrying extra fields (code, label, externalId) where the query tries to compare against the field instead of the enum itself; refactor of numeric status columns into enums; string-built HQL that appends attribute names to literals.
Related errors
- Cannot dereference an entity name
- Unsupported enum type passed to 'ordinal()' function: %s
- path did not map to a column
- Could not resolve attribute '%s' of '%s' due to the attribut
- Unsupported literal: ${literal}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/cf8cbbd2c10a15f2.
Report an issue: GitHub.