{"record":{"id":"863d484e0f2adf2a","repo":"hibernate/hibernate-orm","slug":"summarization-is-not-supported-by-dbms-863d48","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/PostgreSQLLegacySqlAstTranslator.java","lineNumber":260,"sourceCode":"\t\t\t\tappendSql( \"()\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tappendSql( \"(select 1)\" );\n\t\t\t}\n\t\t}\n\t\telse if ( expression instanceof Summarization ) {\n\t\t\tSummarization summarization = (Summarization) expression;\n\t\t\tif ( getDialect().getVersion().isSameOrAfter( 9, 5 ) ) {\n\t\t\t\tappendSql( summarization.getKind().sqlText() );\n\t\t\t\tappendSql( OPEN_PARENTHESIS );\n\t\t\t\trenderCommaSeparated( summarization.getGroupings() );\n\t\t\t\tappendSql( CLOSE_PARENTHESIS );\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// This could theoretically be emulated by rendering all grouping variations of the query and\n\t\t\t\t// connect them via union all but that's probably pretty inefficient and would have to happen\n\t\t\t\t// on the query spec level\n\t\t\t\tthrow new UnsupportedOperationException( \"Summarization is not supported by DBMS\" );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\texpression.accept( this );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void visitLikePredicate(LikePredicate likePredicate) {\n\t\t// We need a custom implementation here because PostgreSQL\n\t\t// uses the backslash character as default escape character\n\t\t// According to the documentation, we can overcome this by specifying an empty escape character\n\t\t// See https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE\n\t\tlikePredicate.getMatchExpression().accept( this );\n\t\tif ( likePredicate.isNegated() ) {\n\t\t\tappendSql( \" not\" );\n\t\t}\n\t\tif ( likePredicate.isCaseSensitive() ) {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacySqlAstTranslator.java#L242-L278","documentation":"PostgreSQLLegacySqlAstTranslator.renderPartitionItem() renders GROUP BY items that are Summarizations (rollup/cube/grouping sets). PostgreSQL only gained native grouping-sets syntax in 9.5, so for earlier versions the translator throws UnsupportedOperationException rather than attempting the (theoretically possible but inefficient) union-all emulation noted in the source comment.","triggerScenarios":"HQL/Criteria with 'group by rollup(...)', 'cube(...)' or 'grouping sets(...)' executed against PostgreSQL 9.4 or older, or a PostgreSQLLegacyDialect whose version was explicitly pinned below 9.5.","commonSituations":"Legacy reporting databases still on old 9.x releases; dialect version pinned via an explicit constructor argument because JDBC metadata detection was disabled (hibernate.temp.use_jdbc_metadata_defaults=false).","solutions":["Upgrade PostgreSQL to 9.5 or newer","If the server is already 9.5+, remove the pinned old dialect version or fix version detection","Emulate rollup manually with union all of the grouped query variants","Compute subtotal/total rows in the application layer"],"exampleFix":"-- before (HQL, on PG < 9.5)\nselect year(e.date), e.dept, sum(e.amount) from Expense e\n group by rollup(year(e.date), e.dept)\n\n-- after: emulate with union all\nselect year(e.date), e.dept, sum(e.amount) from Expense e group by year(e.date), e.dept\nunion all\nselect year(e.date), null, sum(e.amount) from Expense e group by year(e.date)\nunion all\nselect null, null, sum(e.amount) from Expense e","handlingStrategy":"validation","validationCode":"Dialect d = sessionFactory.getJdbcServices().getDialect();\nboolean supportsGroupingSets = !( d instanceof PostgreSQLLegacyDialect pg )\n        || pg.getVersion().isSameOrAfter( 9, 5 );\nif ( !supportsGroupingSets ) {\n    // run the union-all emulation instead of 'group by rollup'\n}","typeGuard":null,"tryCatchPattern":"try {\n    return em.createQuery( rollupHql ).getResultList();\n}\ncatch ( UnsupportedOperationException e ) {\n    if ( e.getMessage() != null && e.getMessage().contains( \"Summarization\" ) ) {\n        // pre-9.5 PostgreSQL: switch to the union-all emulation query\n        return em.createQuery( unionAllHql ).getResultList();\n    }\n    throw e;\n}","preventionTips":["Pin the dialect version to the real server version, or let Hibernate detect it","Guard rollup/cube queries behind a capability check","Test reports against the oldest database version you support"],"tags":["postgresql","group-by","rollup","grouping-sets","version-detection"],"backgroundTag":"grouping-sets-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}