hibernate/hibernate-orm · error · CoercionException

Cannot coerce Float value `%s` to Double : overflow

Error message

Cannot coerce Float value `%s` to Double : overflow

What it means

Guard inside CoercionHelper.toDouble(Float): it throws when floatValue > (float) Double.MAX_VALUE, i.e. a float supposedly too large for a double. In standard Java this branch is effectively unreachable: casting Double.MAX_VALUE to float yields +Infinity, every finite float (even Float.MAX_VALUE) is exactly representable as a double, and neither NaN nor Infinity satisfies a strict > against Infinity. It exists as the symmetric counterpart to the underflow check on the next lines.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CoercionHelper.java:346

		if ( ! isWholeNumber( floatValue ) ) {
			throw new CoercionException(
					String.format(
							Locale.ROOT,
							"Unable to coerce Double Float `%s` as BigInteger: not a whole number",
							floatValue
					)
			);
		}
		return BigInteger.valueOf( floatValue.longValue() );
	}

	public static BigInteger toBigInteger(BigDecimal value) {
		return coerceWrappingError( value::toBigIntegerExact );
	}

	public static Double toDouble(Float floatValue) {
		if ( floatValue > (float) Double.MAX_VALUE ) {
			throw new CoercionException(
					String.format(
							Locale.ROOT,
							"Cannot coerce Float value `%s` to Double : overflow",
							floatValue
					)
			);
		}

		if ( floatValue < (float) Double.MIN_VALUE ) {
			throw new CoercionException(
					String.format(
							Locale.ROOT,
							"Cannot coerce Float value `%s` to Double : underflow",
							floatValue
					)
			);
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. If you believe you hit this, log the exact floatValue and verify no custom/patched CoercionHelper is on the classpath
  2. Sanitize inputs for Float.isInfinite() / Float.isNaN() before binding them
  3. Upgrade to a current hibernate-core 6.x release so the whole Float-to-Double path matches upstream
Defensive patterns

Strategy: validation

Validate before calling

static boolean doubleSafe(Float f) {
    return f != null && f.isFinite(); // infinite/NaN never widen meaningfully
}

Type guard

static boolean isFiniteFloat(Number n) {
    return !(n instanceof Float f) || f.isFinite();
}

Prevention

When it happens

Trigger: Not producible by a plain float on a stock JVM, because (float > +Infinity) is always false; only reachable if a patched or custom CoercionHelper changes the comparison semantics.

Common situations: Essentially never seen in isolation; developers chasing Float-to-Double coercion failures actually hit the sibling 'underflow' throw (the next check) instead.

Related errors


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