{"record":{"id":"343b560c7cbabac9","repo":"hibernate/hibernate-orm","slug":"static-field-reference-s-s-cannot-be-de-refere","errorCode":null,"errorMessage":"Static field reference [%s#%s] cannot be de-referenced","messagePattern":"Static field 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/SqmFieldLiteral.java","lineNumber":117,"sourceCode":"\t\treturn getJavaTypeDescriptor().getJavaTypeClass();\n\t}\n\n\t@Override\n\tpublic <X> X accept(SemanticQueryWalker<X> walker) {\n\t\treturn walker.visitFieldLiteral( this );\n\t}\n\n\t@Override\n\tpublic void appendHqlString(StringBuilder hql, SqmRenderContext context) {\n\t\tSqmLiteral.appendHqlString( hql, getJavaTypeDescriptor(), getValue() );\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 UnknownPathException(\n\t\t\t\tString.format(\n\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\"Static field reference [%s#%s] cannot be de-referenced\",\n\t\t\t\t\t\tfieldJavaType.getTypeName(),\n\t\t\t\t\t\tfieldName\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 field reference [%s#%s] cannot be de-referenced\",","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmFieldLiteral.java#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["End the path at the static field and compare against it directly, or reference the deeper constant by its own fully-qualified name.","Bind values you cannot reference directly as query parameters instead of navigating static structures in HQL.","Fix the path so every segment after the class name is a real field and the static field is the last segment."],"exampleFix":"-- before\nselect o from Order o where o.mask = com.acme.Flags.ALL.mask  -- .mask dereferences a static field\n\n-- after\nselect o from Order o where o.mask = :mask  -- bind com.acme.Flags.ALL.mask in Java","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery( hql, Tuple.class ).getResultList();\n} catch ( org.hibernate.query.sqm.UnknownPathException e ) {\n    // a static-field path was dereferenced - surface the offending type#field\n    throw new BadRequestException( \"Invalid path in query: \" + e.getMessage(), e );\n}","preventionTips":["Treat static field references as terminal: never append further path segments in HQL.","Pass structured constant values as bound parameters rather than navigating them in the query.","Add interpretation tests for every HQL string that contains fully-qualified class names."],"tags":["hibernate","hql","sqm","static-field","path-resolution"],"backgroundTag":"invalid-query-path","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}