hibernate/hibernate-orm · error · UnsupportedOperationException

Summarization is not supported by DBMS

Error message

Summarization is not supported by DBMS

What it means

Cloud Spanner's PostgreSQL interface does not implement grouping sets / rollup / cube. SpannerPostgreSQLSqlAstTranslator.renderPartitionItem throws UnsupportedOperationException('Summarization is not supported by DBMS') when a Summarization expression (rollup/cube/grouping sets from HQL GROUP BY or window PARTITION BY items) has to be rendered. The code comment notes the only emulation -- rendering every grouping variation connected by union all at the query-spec level -- is not implemented.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/sql/ast/SpannerPostgreSQLSqlAstTranslator.java:60

		registerAffectedTable(tableReference);
		// ALWAYS render the alias for the target table since Spanner doesn't support
		// FROM in UPDATE
		final Clause currentClause = getClauseStack().getCurrent();
		if ( currentClause == Clause.UPDATE || currentClause == Clause.DELETE) {
			renderTableReferenceIdentificationVariable(tableReference);
		}
	}

	@Override
	protected void renderPartitionItem(Expression expression) {
		if ( expression instanceof Literal ) {
			appendSql( "'0' || '0'" );
		}
		else if ( expression instanceof Summarization ) {
			// This could theoretically be emulated by rendering all grouping variations of the query and
			// connect them via union all but that's probably pretty inefficient and would have to happen
			// on the query spec level
			throw new UnsupportedOperationException( "Summarization is not supported by DBMS" );
		}
		else {
			expression.accept( this );
		}
	}

	@Override
	protected void renderLikePredicate(LikePredicate likePredicate) {
		// We need a custom implementation here because Spanner
		// uses the backslash character as default escape character
		if (likePredicate.getEscapeCharacter() == null) {
			renderBackslashEscapedLikePattern( likePredicate.getPattern(), likePredicate.getEscapeCharacter(), true );
		}
		else {
			renderLikePattern( likePredicate.getPattern(), likePredicate.getEscapeCharacter() );
		}
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Rewrite the report as one plain GROUP BY query per grouping level and merge the result sets (union all semantics) in application code
  2. Compute totals/subtotals in separate aggregate queries and stitch them together in Java
  3. Export the data to BigQuery (or run against real PostgreSQL) for grouping-sets-heavy reporting instead of Spanner
  4. Pre-materialize the grouped levels into a table via several Spanner queries, then query that table

Example fix

// before (throws on Spanner PostgreSQL)
"select region, product, sum(amount) from Sale s group by rollup (s.region, s.product)"

// after: per-level queries merged in memory
perRegionProduct = em.createQuery("select region, product, sum(amount) ... group by region, product");
perRegion        = em.createQuery("select region, sum(amount) ... group by region");
grandTotal       = em.createQuery("select sum(amount) from Sale s");
Defensive patterns

Strategy: validation

Validate before calling

static boolean supportsSummarization(Dialect dialect) {
    return !(dialect instanceof SpannerPostgreSQLDialect || dialect instanceof SpannerDialect
        || dialect instanceof HSQLDialect || dialect instanceof SybaseASEDialect);
}

if (queryUsesRollup(hql) && !supportsSummarization(dialect)) {
    return analyticsService.expandedGrouping(query); // per-level queries merged in app
}

Try / catch

try {
    return em.createQuery(rollupHql, Object[].class).getResultList();
} catch (UnsupportedOperationException e) {
    if ("Summarization is not supported by DBMS".equals(e.getMessage())) {
        return analyticsService.expandedGrouping(query);
    }
    throw e;
}

Prevention

When it happens

Trigger: Running HQL like 'group by rollup(a,b)', 'group by cube(a,b)' or 'group by grouping sets ((a),(b),())' (or an OVER (PARTITION BY rollup(...)) item) against a SessionFactory configured with SpannerPostgreSQLDialect. Throws during SQL rendering, before execution on Spanner.

Common situations: Moving an analytics/reporting workload from PostgreSQL to Cloud Spanner (PG interface) and keeping the rollup queries; running the same test suite against Spanner PostgreSQL that was written for vanilla PostgreSQL.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/f26ebc3e8847c3f3. Report an issue: GitHub.