hibernate/hibernate-orm · error · UnsupportedOperationException

min() not supported

Error message

min() not supported

What it means

SqmBooleanExpressionImplementor provides default implementations of the Hibernate expression extensions for Boolean-typed nodes; min() is deliberately unsupported because the SQM type system defines no minimum/maximum semantics for Boolean values, so calling it throws UnsupportedOperationException('min() not supported').

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/expression/SqmBooleanExpressionImplementor.java:28

import org.hibernate.query.sqm.tree.spi.predicate.SqmPredicate;

/**
 * @author Steve Ebersole
 */
public interface SqmBooleanExpressionImplementor
		extends SqmComparableExpressionImplementor<Boolean>, SqmBooleanExpression {
	SqmCriteriaNodeBuilder nodeBuilder();

	@Nonnull
	@Override
	default SqmComparableExpression<Boolean> max() {
		throw new UnsupportedOperationException( "max() not supported" );
	}

	@Nonnull
	@Override
	default SqmComparableExpression<Boolean> min() {
		throw new UnsupportedOperationException( "min() not supported" );
	}

	@Nonnull
	@Override
	default SqmPredicate and(@Nonnull Expression<Boolean> y) {
		return nodeBuilder().and( this, y );
	}

	@Nonnull
	@Override
	default SqmPredicate or(@Nonnull Expression<Boolean> y) {
		return nodeBuilder().or( this, y );
	}

	@Nonnull
	@Override
	default SqmPredicate not() {
		return nodeBuilder().not( this );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Rewrite as a numeric aggregate: cb.max(cb.selectCase().when(cb.isTrue(flag), 1).otherwise(0)) (max of the numeric encoding gives the same 'min boolean' information).
  2. Use cb.sum(...) over the case encoding for counting semantics.
  3. Remap the attribute as a numeric type or compute the aggregate in native SQL.
  4. Type-guard aggregation helpers so min()/max() only run on numeric expressions.

Example fix

// before
JpaExpression<Boolean> enabled = root.get("enabled");
query.select(enabled.min()); // UnsupportedOperationException: min() not supported
// after
query.select(cb.max(cb.selectCase().when(cb.isTrue(root.get("enabled")), 0).otherwise(1))); // 0 iff any row enabled
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean numeric(Expression<?> e) {
    return e.getJavaType() != null && Number.class.isAssignableFrom(e.getJavaType());
}
// only call expr.min() when numeric(expr) is true

Type guard

static boolean aggregatableByMinMax(Expression<?> e) {
    Class<?> jt = e.getJavaType();
    return jt != null && Number.class.isAssignableFrom(jt);
}

Prevention

When it happens

Trigger: booleanExpression.min() in Hibernate 6 criteria code, e.g. ((JpaExpression<Boolean>) root.get("enabled")).min() or chained fluent calls on expressions returned by cb.isTrue/cb.isFalse.

Common situations: Aggregation of boolean flags in report queries; generic min/max builders that call both methods on arbitrary comparable expressions; porting native queries where the database accepted min(boolean).

Related errors


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