hibernate/hibernate-orm · error · SemanticException
First operand for contains predicate must be a basic plural…
Error message
First operand for contains predicate must be a basic plural type expression, but found: {} What it means
Thrown by SemanticQueryBuilder while building a 'contains' predicate: the left operand must be an expression of a basic plural type (array/collection), but the resolved SQM type of the supplied lhs expression is something else. The offending input is the lhs expression of the contains predicate, whose actual type is echoed in the message.
Solutions
- Use a basic plural (array/collection of basic values) expression as the first operand of 'contains'.
- Verify the operand type is an array or basic collection.
Defensive patterns
Strategy: validation
When it happens
Trigger: A path expression of the wrong type is used in a collection predicate.
Common situations: Applying member of / is empty / includes / intersects / in-array to non-plural expressions.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/19c79b0b35c07e06.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:2562
if ( firstSymbol.getType() == HqlParser.NOT ) {
negated = true;
operationSymbol = ((TerminalNode) ctx.getChild( 2 )).getSymbol();
}
else {
negated = firstSymbol.getType() == HqlParser.IS
&& ((TerminalNode) ctx.getChild( 2 )).getSymbol().getType() == HqlParser.NOT;
operationSymbol = firstSymbol;
}
final var expressions = ctx.expression();
final var lhsCtx = expressions.get( 0 );
final var rhsCtx = expressions.get( 1 );
return switch ( operationSymbol.getType() ) {
case HqlParser.CONTAINS -> {
final var lhs = (SqmExpression<?>) lhsCtx.accept( this );
final var rhs = (SqmExpression<?>) rhsCtx.accept( this );
final var lhsExpressible = lhs.getExpressible();
if ( lhsExpressible != null && !(lhsExpressible.getSqmType() instanceof BasicPluralType<?, ?>) ) {
throw new SemanticException(
"First operand for contains predicate must be a basic plural type expression, but found: " + lhsExpressible.getSqmType(),
query
);
}
final SelfRenderingSqmFunction<Boolean> contains = getFunctionDescriptor(
"array_contains" ).generateSqmExpression(
asList( lhs, rhs ),
null,
queryEngine()
);
yield new SqmBooleanExpressionPredicate( contains, negated, nodeBuilder() );
}
case HqlParser.INCLUDES -> {
final var lhs = (SqmExpression<?>) lhsCtx.accept( this );
final var rhs = (SqmExpression<?>) rhsCtx.accept( this );
final var lhsExpressible = lhs.getExpressible();
final var rhsExpressible = rhs.getExpressible();
if ( lhsExpressible != null && !( lhsExpressible.getSqmType() instanceof BasicPluralType<?, ?>) ) {View on GitHub (pinned to fad1729dce)