hibernate/hibernate-orm · error · SemanticException
Can't use expression '{} without explicit name in xmlforest
Error message
Can't use expression '{} without explicit name in xmlforest function, because XML element names can only be derived from path expressions. What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:3158
xmlelement.content( visitExpressions( ctx ) );
return xmlelement;
}
@Override
public SqmExpression<?> visitXmlforestFunction(HqlParser.XmlforestFunctionContext ctx) {
final ArrayList<SqmExpression<?>> elementExpressions = new ArrayList<>( ctx.getChildCount() >> 1 );
for ( int i = 2; i < ctx.getChildCount(); i++ ) {
if ( ctx.getChild( i ) instanceof HqlParser.ExpressionOrPredicateContext exprCtx ) {
final var expression = (SqmExpression<?>) exprCtx.accept( this );
if ( i + 2 < ctx.getChildCount() && ctx.getChild( i + 2 ) instanceof HqlParser.IdentifierContext identifierContext ) {
final String name = visitIdentifier( identifierContext );
elementExpressions.add( new SqmNamedExpression<>( expression, name ) );
i += 2;
}
else {
if ( !( expression instanceof SqmPath<?> path )
|| !( path.getModel() instanceof PersistentAttribute<?, ?> attribute ) ) {
throw new SemanticException(
"Can't use expression '" + exprCtx.getText() + " without explicit name in xmlforest function" +
", because XML element names can only be derived from path expressions.",
query
);
}
elementExpressions.add( new SqmNamedExpression<>( expression, attribute.getName() ) );
}
}
}
return nodeBuilder().xmlforest( elementExpressions );
}
@Override
public SqmExpression<?> visitXmlpiFunction(HqlParser.XmlpiFunctionContext ctx) {
final String name = visitIdentifier( ctx.identifier() );
final var exprCtx = ctx.expression();
//noinspection unchecked
return exprCtx == nullView on GitHub (pinned to fad1729dce)
Solutions
- Give the expression an explicit name (AS name) in the xmlforest function.
- Use a path expression so the element name can be derived.
When it happens
Trigger: A runtime precondition of the Hibernate API is violated.
Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e661d874009b1b9c.
Report an issue: GitHub.