hibernate/hibernate-orm · error · IllegalArgumentException
Passed `selectionExpression` for function return cannot be n
Error message
Passed `selectionExpression` for function return cannot be null
What it means
The same invariant(component, BasicTypeReference, selectionExpression) overload also requires a non-null selectionExpression - the output column name/alias the function's row component carries in the result set. Null is rejected immediately with IllegalArgumentException at registration time. The selectionExpression makes each returned column addressable, so it cannot be defaulted silently.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/internal/SetReturningFunctionTypeResolverBuilder.java:56
}
@Override
public SetReturningFunctionTypeResolverBuilder invariant(String component, BasicType<?> invariantType) {
return invariant( component, invariantType, component );
}
@Override
public SetReturningFunctionTypeResolverBuilder useArgType(String component, int argPosition) {
return useArgType( component, argPosition, component );
}
@Override
public SetReturningFunctionTypeResolver.Builder invariant(String component, BasicTypeReference<?> invariantType, String selectionExpression) {
if ( invariantType == null ) {
throw new IllegalArgumentException( "Passed `invariantType` for function return cannot be null" );
}
if ( selectionExpression == null ) {
throw new IllegalArgumentException( "Passed `selectionExpression` for function return cannot be null" );
}
return withComponent( component, new BasicTypeReferenceTypeResolver( component, selectionExpression, invariantType ) );
}
@Override
public SetReturningFunctionTypeResolverBuilder invariant(String component, BasicType<?> invariantType, String selectionExpression) {
if ( invariantType == null ) {
throw new IllegalArgumentException( "Passed `invariantType` for function return cannot be null" );
}
if ( selectionExpression == null ) {
throw new IllegalArgumentException( "Passed `selectionExpression` for function return cannot be null" );
}
return withComponent( component, new BasicTypeTypeResolver( component, selectionExpression, invariantType ) );
}
@Override
public SetReturningFunctionTypeResolverBuilder useArgType(String component, int argPosition, String selectionExpression) {
if ( selectionExpression == null ) {View on GitHub (pinned to fad1729dce)
Solutions
- Pass an explicit selection expression: builder.invariant("value", StandardBasicTypes.STRING, "value").
- Use the shorter overload invariant(component, type), which defaults selectionExpression to the component name.
- Guard with Objects.requireNonNull(selectionExpression, ...) before the call.
Example fix
// before
builder.invariant("value", StandardBasicTypes.STRING, null);
// after
builder.invariant("value", StandardBasicTypes.STRING, "value");
// or let it default to the component name
builder.invariant("value", StandardBasicTypes.STRING); Defensive patterns
Strategy: validation
Validate before calling
String selection = Objects.requireNonNullElse(selectionExpression, component); builder.invariant(component, type, selection);
Try / catch
try {
builder.invariant(component, type, selection);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Incomplete set-returning function definition: " + e.getMessage(), e);
} Prevention
- Prefer the 2-arg overloads that default selectionExpression to the component name.
- Never omit the third argument of a 3-arg overload; use the shorter overload instead.
- Validate config-derived aliases before building.
When it happens
Trigger: builder.invariant("value", StandardBasicTypes.STRING, null) - the third argument was omitted or never set when defining a set-returning function's row component.
Common situations: Chained builder calls where the alias argument was dropped during refactoring; assuming the 3-arg overload derives the alias from the component name (only the 2-arg overloads do that).
Related errors
- Passed `invariantType` for function return cannot be null
- Passed `component` for function return cannot be null
- Passed `invariantType` for function return cannot be null
- The specified package name cannot be null
- Named query definition is null
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/65dd1f9048b682b1.
Report an issue: GitHub.