hibernate/hibernate-orm · error · HibernateException

could not determine transaction status in beforeCompletion()

Error message

could not determine transaction status in beforeCompletion()

What it means

Thrown during JTA beforeCompletion processing when calling getJtaPlatform().getCurrentStatus() raised a SystemException, so Hibernate cannot decide whether to flush before transaction completion.

Solutions

  1. Ensure the transaction is still active in beforeCompletion(); avoid completing/rolling back the transaction before synchronization callbacks run.
  2. Check transaction status via Transaction.getStatus() before operations in afterBegin/beforeCompletion.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1800 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1800

	public TransactionCompletionCallbacks getTransactionCompletionCallbacks() {
		return transactionCompletionCallbacks;
	}

	@Override
	public void flushBeforeTransactionCompletion() {
		if ( shouldFlushBeforeCompletion() ) {
			managedFlush();
		}
	}

	private boolean shouldFlushBeforeCompletion() {
		try {
			return !isClosed()
				&& !isFlushModeNever()
				&& !isRollback( getJtaPlatform().getCurrentStatus() );
		}
		catch ( SystemException se ) {
			throw new HibernateException( "could not determine transaction status in beforeCompletion()", se );
		}
	}

	private JtaPlatform getJtaPlatform() {
		return getFactory().getServiceRegistry().requireService( JtaPlatform.class );
	}

	private LockMode getNullSafeLockMode(LockMode lockMode) {
		return lockMode == null ? LockMode.NONE : lockMode;
	}

	protected Object lockCacheItem(Object id, Object previousVersion, EntityPersister persister) {
		return writingToCache( persister, cache -> {
			final Object cacheKey = cache.generateCacheKey(
					id,
					persister,
					getFactory(),
					getTenantIdentifier()

View on GitHub (pinned to fad1729dce)