hibernate/hibernate-orm · error · FunctionArgumentException
Parameter %d of function 'xmlforest()' is not named
Error message
Parameter %d of function 'xmlforest()' is not named
What it means
The 'xmlforest()' HQL function must emit one XML element per argument, and each element needs a tag name, so every argument has to be an aliased (named) expression (SqmNamedExpression). During SQM validation XmlForestFunction iterates the arguments and throws FunctionArgumentException with the 0-based parameter position when argument i carries no alias. This fails at query translation time, before SQL generation.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/xml/XmlForestFunction.java:46
* Standard xmlforest function.
*/
public class XmlForestFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
public XmlForestFunction(TypeConfiguration typeConfiguration) {
super(
"xmlforest",
FunctionKind.NORMAL,
StandardArgumentsValidators.composite(
StandardArgumentsValidators.min( 1 ),
new ArgumentsValidator() {
@Override
public void validate(
List<? extends SqmTypedNode<?>> arguments,
String functionName,
BindingContext bindingContext) {
for ( int i = 0; i < arguments.size(); i++ ) {
if ( !( arguments.get( i ) instanceof SqmNamedExpression<?> namedExpression ) ) {
throw new FunctionArgumentException(
String.format(
"Parameter %d of function 'xmlforest()' is not named",
i
)
);
}
if ( !XmlHelper.isValidXmlName( namedExpression.getName() ) ) {
throw new FunctionArgumentException(
String.format(
"Invalid XML element name passed to 'xmlforest()': %s",
namedExpression.getName()
)
);
}
}
}
}View on GitHub (pinned to fad1729dce)
Solutions
- Alias every argument of xmlforest(): select xmlforest(p.name as "name", p.age as "age") from Person p
- If you build HQL dynamically, assert each contributed fragment inside xmlforest(...) contains ' as <alias>'
- If you do not need per-element names, use a different construction (e.g. xmlelement or client-side mapping) since xmlforest fundamentally requires names
Example fix
// before select xmlforest(p.name, p.age) from Person p // after select xmlforest(p.name as "name", p.age as "age") from Person p
Defensive patterns
Strategy: validation
Validate before calling
// Before building xmlforest(...) fragments, ensure every argument is aliased
boolean allAliased = args.stream().allMatch(a -> a.contains(" as "));
if (!allAliased) {
throw new IllegalArgumentException("every xmlforest() argument needs an alias, e.g. p.name as \"name\"");
} Try / catch
try {
return session.createQuery(hql, String.class).list();
}
catch (FunctionArgumentException e) {
// e.getMessage() contains the 0-based parameter index
throw new IllegalArgumentException("xmlforest() argument not aliased: " + e.getMessage(), e);
} Prevention
- Treat xmlforest() like a projection: every expression gets an alias that becomes the XML tag name
- Lint generated HQL in CI with a parser or a regex check for unaliased arguments inside xmlforest(...)
- Keep xmlforest calls in one query-building module so aliasing cannot be forgotten at call sites
When it happens
Trigger: Calling xmlforest() with plain, unaliased expressions: select xmlforest(p.name, p.age) from Person p - argument 0 ('p.name') is not named, so 'Parameter 0 of function 'xmlforest()' is not named' is thrown. Also happens when a dynamic query builder omits the 'as alias' clause for one of several arguments.
Common situations: Copying native SQL/XML 'xmlforest()' calls into HQL (SQL dialects can derive names from column labels, Hibernate cannot); refactoring a select list and dropping aliases; criteria/HQL generated from reflection over field names without aliasing.
Related errors
- Invalid XML element name passed to 'xmlforest()': %s
- Invalid XML attribute name passed to 'xmlattributes()': %s
- Function %s() has %d parameters, but %d arguments given
- Can't use expression '" + expression + " without explicit na
- Insert conflict 'do update' clause with constraint name is n
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/2445b72cdce10e38.
Report an issue: GitHub.