hibernate/hibernate-orm · error · TransactionException

Unable to apply requested transaction timeout

Error message

Unable to apply requested transaction timeout

What it means

setTimeOut forwards positive values to UserTransaction.setTransactionTimeout(seconds); a SystemException is wrapped as 'Unable to apply requested transaction timeout'. The UT/TM refused or failed the request - commonly a value outside the TM's allowed range, a call made too late (after begin), or a TM error. Values <= 0 are silently ignored because of the seconds > 0 guard.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionAdapterUserTransactionImpl.java:118

	@Override
	public void markRollbackOnly(){
		try {
			userTransaction.setRollbackOnly();
		}
		catch (SystemException e) {
			throw new TransactionException( "Unable to mark transaction for rollback only", e );
		}
	}

	@Override
	public void setTimeOut(int seconds) {
		if ( seconds > 0 ) {
			try {
				userTransaction.setTransactionTimeout( seconds );
			}
			catch (SystemException e) {
				throw new TransactionException( "Unable to apply requested transaction timeout", e );
			}
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass seconds within the TM's allowed range
  2. Raise the TM maximum timeout if the value is legitimate
  3. Set the timeout before the transaction begins
  4. Check TM logs for the underlying SystemException

Example fix

// before
ut.setTransactionTimeout(30_000); // ms-as-seconds, exceeds TM limits

// after
ut.setTransactionTimeout(30); // seconds
Defensive patterns

Strategy: validation

Validate before calling

// Clamp to a sane seconds range before applying
int seconds = Math.min(Math.max(requestedSeconds, 1), tmMaxTimeoutSeconds);
if ( seconds > 0 ) {
    session.getTransaction().setTimeout(seconds);
}

Try / catch

try {
    session.getTransaction().setTimeout(seconds);
}
catch (TransactionException e) {
    log.warn("UT rejected timeout {}s; continuing with default", seconds, e);
}

Prevention

When it happens

Trigger: Transaction.setTimeout(n) with n > 0, typically applied per-transaction before begin or via BMT timeout configuration, when userTransaction.setTransactionTimeout throws SystemException.

Common situations: Milliseconds passed where seconds are expected; exceeding the TM maximum timeout; setting the timeout after the transaction began; UT context restrictions.

Understand the failure class

Related errors


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