{"record":{"id":"cf8cbbd2c10a15f2","repo":"hibernate/hibernate-orm","slug":"static-enum-reference-s-s-cannot-be-de-referen","errorCode":null,"errorMessage":"Static enum reference [%s#%s] cannot be de-referenced","messagePattern":"Static enum reference \\[(.+?)#(.+?)\\] cannot be de-referenced","errorType":"exception","errorClass":"UnknownPathException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmEnumLiteral.java","lineNumber":110,"sourceCode":"\tpublic EnumJavaType<E> getExpressibleJavaType() {\n\t\treturn referencedEnumTypeDescriptor;\n\t}\n\n\t@Override\n\tpublic Class<E> getJavaType() {\n\t\treturn referencedEnumTypeDescriptor.getJavaTypeClass();\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// SemanticPathPart\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 UnknownPathException(\n\t\t\t\tString.format(\n\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\"Static enum reference [%s#%s] cannot be de-referenced\",\n\t\t\t\t\t\treferencedEnumTypeDescriptor.getTypeName(),\n\t\t\t\t\t\tenumValueName\n\t\t\t\t)\n\t\t);\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 UnknownPathException(\n\t\t\t\tString.format(\n\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\"Static enum reference [%s#%s] cannot be de-referenced\",","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmEnumLiteral.java#L92-L128","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"-- before (HQL)\nfrom Order o where o.statusCode = StatusCode.APPROVED.code\n-- after\nfrom Order o where o.statusCode = :code\n// Java: query.setParameter(\"code\", StatusCode.APPROVED.getCode())","handlingStrategy":"try-catch","validationCode":"// Lint HQL: enum constant followed by another member (Enum.CONSTANT.member) is invalid\nstatic boolean hqlDereferencesEnumLiteral(String hql) {\n    return hql.matches(\"(?s).*\\\\b[A-Z]\\\\w*\\\\.[A-Z][A-Z0-9_]*\\\\.[a-zA-Z]\\\\w*.*\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return em.createQuery(hql, resultClass);\n} catch (UnknownPathException badPath) { // org.hibernate.query.UnknownPathException\n    throw new IllegalArgumentException(\"Enum literal dereferenced in query: \" + hql, badPath);\n}","preventionTips":["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."],"tags":["hibernate","hql","enum","path-resolution","literal","query-interpretation"],"backgroundTag":"enum-literal-dereference","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}