{"record":{"id":"e661d874009b1b9c","repo":"hibernate/hibernate-orm","slug":"can-t-use-expression-without-explicit-name-in","errorCode":null,"errorMessage":"Can't use expression '{} without explicit name in xmlforest function, because XML element names can only be derived from path expressions.","messagePattern":"Can't use expression '(.+?) without explicit name in xmlforest function, because XML element names can only be derived from path expressions\\.","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":3158,"sourceCode":"\t\txmlelement.content( visitExpressions( ctx ) );\n\t\treturn xmlelement;\n\t}\n\n\t@Override\n\tpublic SqmExpression<?> visitXmlforestFunction(HqlParser.XmlforestFunctionContext ctx) {\n\t\tfinal ArrayList<SqmExpression<?>> elementExpressions = new ArrayList<>( ctx.getChildCount() >> 1 );\n\t\tfor ( int i = 2; i < ctx.getChildCount(); i++ ) {\n\t\t\tif ( ctx.getChild( i ) instanceof HqlParser.ExpressionOrPredicateContext exprCtx ) {\n\t\t\t\tfinal var expression = (SqmExpression<?>) exprCtx.accept( this );\n\t\t\t\tif ( i + 2 < ctx.getChildCount() && ctx.getChild( i + 2 ) instanceof HqlParser.IdentifierContext identifierContext ) {\n\t\t\t\t\tfinal String name = visitIdentifier( identifierContext );\n\t\t\t\t\telementExpressions.add( new SqmNamedExpression<>( expression, name ) );\n\t\t\t\t\ti += 2;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif ( !( expression instanceof SqmPath<?> path )\n\t\t\t\t\t\t\t|| !( path.getModel() instanceof PersistentAttribute<?, ?> attribute ) ) {\n\t\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\t\"Can't use expression '\" + exprCtx.getText() + \" without explicit name in xmlforest function\" +\n\t\t\t\t\t\t\t\t\t\t\", because XML element names can only be derived from path expressions.\",\n\t\t\t\t\t\t\t\tquery\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\telementExpressions.add( new SqmNamedExpression<>( expression, attribute.getName() ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn nodeBuilder().xmlforest( elementExpressions );\n\t}\n\n\t@Override\n\tpublic SqmExpression<?> visitXmlpiFunction(HqlParser.XmlpiFunctionContext ctx) {\n\t\tfinal String name = visitIdentifier( ctx.identifier() );\n\t\tfinal var exprCtx = ctx.expression();\n\t\t//noinspection unchecked\n\t\treturn exprCtx == null","sourceCodeStart":3140,"sourceCodeEnd":3176,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L3140-L3176","documentation":"Error \"Can't use expression '{} without explicit name in xmlforest function, because XML element names can only be derived from path expressions.\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Give the expression an explicit name (AS name) in the xmlforest function.","Use a path expression so the element name can be derived."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}