{"record":{"id":"8cdefda16fa7f4af","repo":"hibernate/hibernate-orm","slug":"summarization-is-not-supported-by-dbms-8cdefd","errorCode":null,"errorMessage":"Summarization is not supported by DBMS","messagePattern":"Summarization is not supported by DBMS","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/H2LegacySqlAstTranslator.java","lineNumber":300,"sourceCode":"\t\tif ( renderAsArray ) {\n\t\t\tappend( OPEN_PARENTHESIS );\n\t\t}\n\t\tsuper.visitSqlSelections( selectClause );\n\t\tif ( renderAsArray ) {\n\t\t\tappend( CLOSE_PARENTHESIS );\n\t\t}\n\t}\n\n\t@Override\n\tprotected void renderPartitionItem(Expression expression) {\n\t\tif ( expression instanceof Literal ) {\n\t\t\tappendSql( \"'0' || '0'\" );\n\t\t}\n\t\telse if ( expression instanceof Summarization ) {\n\t\t\t// This could theoretically be emulated by rendering all grouping variations of the query and\n\t\t\t// connect them via union all but that's probably pretty inefficient and would have to happen\n\t\t\t// on the query spec level\n\t\t\tthrow new UnsupportedOperationException( \"Summarization is not supported by DBMS\" );\n\t\t}\n\t\telse {\n\t\t\texpression.accept( this );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {\n\t\tappendSql( OPEN_PARENTHESIS );\n\t\tvisitArithmeticOperand( arithmeticExpression.getLeftHandOperand() );\n\t\tappendSql( arithmeticExpression.getOperator().getOperatorSqlTextString() );\n\t\tvisitArithmeticOperand( arithmeticExpression.getRightHandOperand() );\n\t\tappendSql( CLOSE_PARENTHESIS );\n\t}\n\n\t@Override\n\tprotected void visitArithmeticOperand(Expression expression) {\n\t\trender( expression, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER );","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/H2LegacySqlAstTranslator.java#L282-L318","documentation":"HQL grouping-set constructs - 'group by rollup(...)', 'cube(...)', 'grouping sets(...)' - become a Summarization AST node. H2LegacySqlAstTranslator.renderPartitionItem must render such expressions when emulating aggregate/window machinery, and for Summarization it throws UnsupportedOperationException: the legacy H2 translator contains no grouping-sets emulation (the source comment notes only an impractical union-all rewrite exists).","triggerScenarios":"HQL with rollup/cube/grouping sets executed under the H2 legacy dialect, e.g. 'select d.name, count(e) from Employee e join e.dept d group by rollup(d.name)', particularly when surrounding query elements (window functions, tuple comparisons) force partition-item rendering.","commonSituations":"Reporting/subtotal queries written on newer databases but executed in H2-based legacy test suites; migrating an app to Hibernate 6/7 where the H2 test database stayed on the legacy dialect; analytics code sharing between production PostgreSQL and H2 staging.","solutions":["Expand the rollup/cube into an explicit UNION ALL of plain group-by queries (one per grouping variation)","Switch the H2 database to the non-legacy dialect (H2 2.x), which supports grouping-set rendering","Precompute subtotals (summary table or in-Java aggregation over detail rows)","Branch the report query per database and use plain group-by on the H2 legacy profile"],"exampleFix":"// before (HQL, throws on H2 legacy dialect)\nselect d.name, count(e) from Employee e join e.dept d group by rollup(d.name)\n\n// after (explicit union of variations)\nselect d.name, count(e) from Employee e join e.dept d group by d.name\nunion all\nselect null, count(e) from Employee e","handlingStrategy":"validation","validationCode":"Dialect d = sessionFactory.getJdbcServices().getDialect();\nif (d instanceof org.hibernate.community.dialect.H2LegacyDialect\n        && (hql.contains(\"rollup(\") || hql.contains(\"cube(\") || hql.contains(\"grouping sets\"))) {\n    hql = expandToUnionAll(hql);\n}","typeGuard":"static boolean groupingSetsSafe(Dialect d) {\n    return !(d instanceof org.hibernate.community.dialect.H2LegacyDialect);\n}","tryCatchPattern":"try {\n    rows = session.createQuery(hql).getResultList(); // rollup/cube/grouping sets\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage().contains(\"Summarization\")) {\n        // re-run as union-all of plain group-by queries\n    } else throw e;\n}","preventionTips":["Run grouping-set analytics on the non-legacy H2 dialect or the production database, not the legacy profile","Wrap rollup/cube queries in per-dialect repository methods","Compute totals/subtotals in Java when the detail set is already loaded"],"tags":["hibernate","h2","legacy-dialect","hql","grouping-sets","rollup","aggregation"],"backgroundTag":"grouping-sets-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}