{"record":{"id":"78f3374a86cd3411","repo":"hibernate/hibernate-orm","slug":"operand-of-op-getoperatorsqltext-is-of-t-78f337","errorCode":null,"errorMessage":"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[]')","messagePattern":"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\\[\\]'\\)","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/internal/TypecheckUtil.java","lineNumber":588,"sourceCode":"\t\t\t\t\t\t\t\t// we can subtract a duration from a date, time, or datetime\n\t\t\t\t\t\t\t\t&& !TemporalAmount.class.isAssignableFrom( rightJavaType ) ) {\n\t\t\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\t\t\"Operand of \" + op.getOperatorSqlText() + \" is of type '\" + rightNodeType.getTypeName() +\n\t\t\t\t\t\t\t\t\t\t\t\"' which is not a temporal amount (it is not an instance of 'java.time.TemporalAmount')\"\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\t\"Operand of \" + op.getOperatorSqlText() + \" is of type '\" + leftNodeType.getTypeName() +\n\t\t\t\t\t\t\t\t\t\t\"' which is not a numeric type (it is not an instance of 'java.lang.Number')\"\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( isNumberArray( leftNodeType ) ) {\n\t\t\t\t// left operand is a number\n\t\t\t\tif ( !isNumberArray( rightNodeType ) ) {\n\t\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\t\"Operand of \" + op.getOperatorSqlText() + \" is of type '\" + rightNodeType.getTypeName() +\n\t\t\t\t\t\t\t\t\t\"' which is not a numeric array type\" + \" (it is not an instance of 'java.lang.Number[]')\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\t\"Operand of \" + op.getOperatorSqlText()\n\t\t\t\t\t\t\t\t+ \" is of type '\" + leftNodeType.getTypeName() + \"' which is not a numeric type\"\n\t\t\t\t\t\t\t\t+ \" (it is not an instance of 'java.lang.Number', 'java.time.Temporal', or 'java.time.TemporalAmount')\"\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static boolean isNumberArray(@Nullable SqmExpressible<?> expressible) {\n\t\tif ( expressible != null ) {\n\t\t\tfinal var domainType = expressible.getSqmType();","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/TypecheckUtil.java#L570-L606","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":"// before\nwhere e.scores + 1 is not null\n\n// after\nwhere array_contains(e.scores, 1) = true","handlingStrategy":"type-guard","validationCode":"// Verify both array attributes have numeric element types before arithmetic\nstatic boolean isNumericArray(Class<?> javaType) {\n    return javaType.isArray() && Number.class.isAssignableFrom(javaType.getComponentType());\n}","typeGuard":"static boolean numericArraysBoth(Attribute<?, ?> a, Attribute<?, ?> b) {\n    return isNumericArray(a.getJavaType()) && isNumericArray(b.getJavaType());\n}","tryCatchPattern":"try {\n    return em.createQuery(hql).getResultList();\n} catch (org.hibernate.query.SemanticException e) {\n    throw new QueryBuildException(\"Array arithmetic needs numeric arrays on both sides: \" + hql, e);\n}","preventionTips":["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[])"],"tags":["hql","arrays","type-checking","hibernate-6","jdbc-type-code"],"backgroundTag":"query-operand-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}