hibernate/hibernate-orm · error · IllegalOutputTypeException

Cannot treat UpdateCountOutput as ResultSetOutput

Error message

Cannot treat UpdateCountOutput as ResultSetOutput

What it means

Type-narrowing guard on procedure outputs: asResultSetOutput() was invoked on an UpdateCountOutput, which models an affected-row count and has no underlying ResultSet. The safe-narrowing pattern throws instead of returning null; the faulty input is the Output instance whose actual kind contradicts the requested view. Use asUpdateCountOutput()/getUpdateCount() instead.

Solutions

  1. Check the output type before casting: use outputs.getCurrent() instanceof ResultSetOutput.
  2. Advance through outputs with goToNext() until a result-set output is current.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: An API operation is invoked on an object that does not support it.

Common situations: Using query/procedure/proxy APIs beyond their supported feature set (e.g. scrolling, locking, unwrapping a procedure call).


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/procedure/UpdateCountOutput.java:23

package org.hibernate.procedure;

import jakarta.persistence.sql.ResultSetMapping;

/// Models a return that is an update count (count of rows affected)
///
/// @author Steve Ebersole
public interface UpdateCountOutput extends Output {
	/// Retrieve the associated update count
	int getUpdateCount();

	@Override
	default UpdateCountOutput asUpdateCountOutput() {
		return this;
	}

	@Override
	default ResultSetOutput<?> asResultSetOutput() {
		throw new  IllegalOutputTypeException( "Cannot treat UpdateCountOutput as ResultSetOutput" );
	}

	@Override
	default <X> ResultSetOutput<X> asResultSetOutput(Class<X> resultType) {
		throw new  IllegalOutputTypeException( "Cannot treat UpdateCountOutput as ResultSetOutput" );
	}

	@Override
	default <X> ResultSetOutput<X> asResultSetOutput(ResultSetMapping<X> resultSetMapping) {
		throw new  IllegalOutputTypeException( "Cannot treat UpdateCountOutput as ResultSetOutput" );
	}
}

View on GitHub (pinned to fad1729dce)