{"record":{"id":"4c81f73471b84cc9","repo":"hibernate/hibernate-orm","slug":"can-t-interpret-expression","errorCode":null,"errorMessage":"Can't interpret expression: ","messagePattern":"Can't interpret expression: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java","lineNumber":677,"sourceCode":"\t\t\t\tthrow new IllegalArgumentException( \"Can't interpret expression because no parameter bindings are available\" );\n\t\t\t}\n\t\t\treturn (R) getParameterBindValue( (JdbcParameter) parameterInterpretation.getResolvedExpression() );\n\t\t}\n\t\telse if ( expression instanceof FunctionExpression functionExpression ) {\n\t\t\tif ( \"concat\".equals( functionExpression.getFunctionName() ) ) {\n\t\t\t\tfinal List<? extends SqlAstNode> arguments = functionExpression.getArguments();\n\t\t\t\tfinal StringBuilder sb = new StringBuilder();\n\t\t\t\tfor ( SqlAstNode argument : arguments ) {\n\t\t\t\t\tfinal Object argumentLiteral = interpretExpression( (Expression) argument, jdbcParameterBindings );\n\t\t\t\t\tif ( argumentLiteral == null ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tsb.append( argumentLiteral );\n\t\t\t\t}\n\t\t\t\treturn (R) sb.toString();\n\t\t\t}\n\t\t}\n\t\tthrow new UnsupportedOperationException( \"Can't interpret expression: \" + expression );\n\t}\n\n\tprotected void renderExpressionAsLiteral(Expression expression, JdbcParameterBindings jdbcParameterBindings) {\n\t\tif ( expression instanceof Literal ) {\n\t\t\texpression.accept( this );\n\t\t\treturn;\n\t\t}\n\t\telse if ( expression instanceof JdbcParameter parameter ) {\n\t\t\tif ( jdbcParameterBindings == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Can't interpret expression because no parameter bindings are available\" );\n\t\t\t}\n\t\t\trenderAsLiteral( parameter, getParameterBindValue( parameter ) );\n\t\t\treturn;\n\t\t}\n\t\telse if ( expression instanceof SqmParameterInterpretation parameterInterpretation ) {\n\t\t\tif ( jdbcParameterBindings == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Can't interpret expression because no parameter bindings are available\" );\n\t\t\t}","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java#L659-L695","documentation":"Thrown from AbstractSqlAstTranslator.interpretExpression while SQL is being generated, when a dialect emulation needs the concrete Java value of an expression (constant folding). The interpreter only handles Literal, bound JdbcParameter / SqmParameterInterpretation, and exactly one function, 'concat'; every other node type (arithmetic, CASE, most function calls, subqueries) falls through to 'throw new UnsupportedOperationException(\"Can't interpret expression: \" + expression)'. The message appends the expression's toString(), which tells you which node could not be folded.","triggerScenarios":"Executing a query on a dialect whose translator must inline real values during rendering (limit/offset inlining, function or predicate emulations that call getLiteralValue()/interpretExpression), where the expression in that position is anything other than a literal, a bound parameter, or a concat() tree — e.g. coalesce()/substring()/CASE/arithmetic inside the emulated fragment.","commonSituations":"Combining pagination or dialect-specific emulations with expressions the translator cannot fold; upgrading hibernate-core and hitting a newly active emulation path; custom dialects overriding interpretExpression; HQL that works on PostgreSQL but fails on H2/SQL Server/Oracle because only the latter's translator needs the value.","solutions":["Rewrite the HQL/JPQL so the offending position holds a literal or plain column instead of a function/CASE/arithmetic expression (compute the value in Java and bind it as a parameter that the emulation can resolve).","Move the expression out of the emulated fragment (e.g., out of the ORDER BY / FETCH / emulated predicate) so no interpretation is needed.","Run the statement as a native SQL query (createNativeQuery) where the dialect emulation path is bypassed.","Upgrade hibernate-core — the set of foldable expressions and which dialects need folding changes between minor versions.","If you maintain a custom dialect, override interpretExpression in your SqlAstTranslator subclass to handle the node type."],"exampleFix":"// before — dialect emulation must interpret the CASE expression and fails\nList<Employee> es = session.createQuery(\n    \"select e from Employee e order by case when e.alias is null then e.name else e.alias end\",\n    Employee.class).list();\n\n// after — do the folding in Java and bind the result so only literals/parameters remain\nList<Employee> es = session.createQuery(\n    \"select e from Employee e where e.name = :effectiveName\",\n    Employee.class).setParameter(\"effectiveName\", effective).list();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    List<Employee> rows = query.list();\n} catch (org.hibernate.query.IllegalQueryOperationException | UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Can't interpret expression\")) {\n        // dialect cannot constant-fold this expression: fall back to native SQL or simplify the query\n        log.warn(\"Unsupported expression for dialect emulation: {}\", e.getMessage());\n        rows = runNativeFallback();\n    } else { throw e; }\n}","preventionTips":["Keep emulated positions (limit clauses, emulated functions) free of CASE/arithmetic/non-concat function expressions; prefer literals or bound parameters.","Test queries against the production dialect, not just H2, in CI.","Pin hibernate-core versions and read migration notes before upgrading — emulation coverage changes between minors."],"tags":["hibernate","orm","sql-translation","dialect-emulation","unsupported-operation"],"backgroundTag":"sql-expression-interpretation-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}