hibernate/hibernate-orm · error · SemanticException
Operand of " + op.getOperatorSqlText() + " is of type '" + r
Error message
Operand of " + op.getOperatorSqlText() + " is of type '" + rightNodeType.getTypeName() + "' which is not a numeric array type (it is not an instance of 'java.lang.Number[]')
What it means
Hibernate 6 maps basic array attributes (e.g. int[]/Integer[] annotated @JdbcTypeCode(SqlTypes.ARRAY)). Binary arithmetic is only permitted between two numeric arrays (isNumberArray on both sides); when the left operand is a numeric array and the right is not, this SemanticException is thrown.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/internal/TypecheckUtil.java:588
// we can subtract a duration from a date, time, or datetime
&& !TemporalAmount.class.isAssignableFrom( rightJavaType ) ) {
throw new SemanticException(
"Operand of " + op.getOperatorSqlText() + " is of type '" + rightNodeType.getTypeName() +
"' which is not a temporal amount (it is not an instance of 'java.time.TemporalAmount')"
);
}
break;
default:
throw new SemanticException(
"Operand of " + op.getOperatorSqlText() + " is of type '" + leftNodeType.getTypeName() +
"' which is not a numeric type (it is not an instance of 'java.lang.Number')"
);
}
}
else if ( isNumberArray( leftNodeType ) ) {
// left operand is a number
if ( !isNumberArray( rightNodeType ) ) {
throw new SemanticException(
"Operand of " + op.getOperatorSqlText() + " is of type '" + rightNodeType.getTypeName() +
"' which is not a numeric array type" + " (it is not an instance of 'java.lang.Number[]')"
);
}
}
else {
throw new SemanticException(
"Operand of " + op.getOperatorSqlText()
+ " is of type '" + leftNodeType.getTypeName() + "' which is not a numeric type"
+ " (it is not an instance of 'java.lang.Number', 'java.time.Temporal', or 'java.time.TemporalAmount')"
);
}
}
}
public static boolean isNumberArray(@Nullable SqmExpressible<?> expressible) {
if ( expressible != null ) {
final var domainType = expressible.getSqmType();View on GitHub (pinned to fad1729dce)
Solutions
- For appending elements use `array_append(e.scores, e.newScore)` (Hibernate 6.6+)
- Pass an actual numeric array parameter so both sides are numeric arrays
- Do array manipulation in Java and persist the result instead of in HQL
Example fix
// before where e.scores + 1 is not null // after where array_contains(e.scores, 1) = true
Defensive patterns
Strategy: type-guard
Validate before calling
// Verify both array attributes have numeric element types before arithmetic
static boolean isNumericArray(Class<?> javaType) {
return javaType.isArray() && Number.class.isAssignableFrom(javaType.getComponentType());
} Type guard
static boolean numericArraysBoth(Attribute<?, ?> a, Attribute<?, ?> b) {
return isNumericArray(a.getJavaType()) && isNumericArray(b.getJavaType());
} Try / catch
try {
return em.createQuery(hql).getResultList();
} catch (org.hibernate.query.SemanticException e) {
throw new QueryBuildException("Array arithmetic needs numeric arrays on both sides: " + hql, e);
} Prevention
- Annotate array attributes explicitly with @JdbcTypeCode(SqlTypes.ARRAY)
- Use array_append/array_contains (Hibernate 6.6+) instead of '+' for element ops
- Match parameter types to the array attribute type exactly (int[] vs Integer[])
When it happens
Trigger: `e.scores + e.newScore` (array + scalar); `e.scores + e.labels` (String[] right side); binary arithmetic where the left attribute maps to Number[] and the right does not map to a numeric array type.
Common situations: Using '+' hoping for array concatenation (HQL/PostgreSQL habit); Hibernate 6.4+ array support newly adopted, with queries written against scalar parameters; mixing element values with array columns in predicates.
Related errors
- Operand of " + op.getOperatorSqlText() + " is of type '" + r
- Operand of " + op.getOperatorSqlText() + " is of type '" + r
- Operand of " + op.getOperatorSqlText() + " is of type '" + r
- Operand of " + op.getOperatorSqlText() + " is of type '" + l
- Operand of " + op.getOperatorSqlText() + " is of type '" + l
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/78f3374a86cd3411.
Report an issue: GitHub.