{"record":{"id":"c5d685c84e668d5f","repo":"hibernate/hibernate-orm","slug":"jta-usertransaction-commit-failed","errorCode":null,"errorMessage":"JTA UserTransaction.commit() failed","messagePattern":"JTA UserTransaction\\.commit\\(\\) failed","errorType":"exception","errorClass":"TransactionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionAdapterUserTransactionImpl.java","lineNumber":64,"sourceCode":"\t\t\tthrow new TransactionException( \"JTA UserTransaction.begin() failed\", e );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void commit() {\n\t\ttry {\n\t\t\tif ( initiator ) {\n\t\t\t\tinitiator = false;\n\t\t\t\tJTA_LOGGER.callingUserTransactionCommit();\n\t\t\t\tuserTransaction.commit();\n\t\t\t\tJTA_LOGGER.calledUserTransactionCommit();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tJTA_LOGGER.skippingTransactionManagerCommit();\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new TransactionException( \"JTA UserTransaction.commit() failed\", e );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void rollback() {\n\t\ttry {\n\t\t\tif ( initiator ) {\n\t\t\t\tinitiator = false;\n\t\t\t\tJTA_LOGGER.callingUserTransactionRollback();\n\t\t\t\tuserTransaction.rollback();\n\t\t\t\tJTA_LOGGER.calledUserTransactionRollback();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmarkRollbackOnly();\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new TransactionException( \"JTA UserTransaction.rollback() failed\", e );","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionAdapterUserTransactionImpl.java#L46-L82","documentation":"UserTransaction.commit() threw and is wrapped in this TransactionException, surfaced from Transaction.commit() on a coordinator that drives UserTransaction. Typical wrapped causes: RollbackException (the transaction was marked rollback-only earlier, frequently by a swallowed application error), HeuristicMixedException/HeuristicRollbackException, SystemException, SecurityException, or IllegalStateException. As with the TransactionManager variant, the initiator flag is cleared before commit, so the commit is not retried.","triggerScenarios":"tx.commit() after the JTA transaction was marked rollback-only; an XA heuristic outcome at commit; commit called with no active transaction, from a disallowed security context (SecurityException), or the wrong thread.","commonSituations":"Ignoring a persistence exception and still committing in bean-managed transactions; a UT/TM timeout completing the transaction before the commit; security restrictions on BMT commit.","solutions":["Locate the earlier rollback-only cause in the logs and fix it; the commit failure is downstream of it","Let failures propagate and roll back instead of committing anyway","Resolve TM heuristic entries when the cause is a Heuristic*Exception","Ensure the calling context is permitted to commit the UserTransaction"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Know the tx is committable before committing\nTransactionStatus st = session.getTransaction().getStatus();\nif ( st != TransactionStatus.ACTIVE ) {\n    throw new IllegalStateException(\"Cannot commit: tx status \" + st);\n}","typeGuard":null,"tryCatchPattern":"catch (TransactionException e) {\n    Throwable c = e.getCause();\n    if ( c instanceof RollbackException ) {\n        // find the original rollback-only cause earlier in the logs\n    }\n    else if ( c instanceof SecurityException ) {\n        // the calling context is not allowed to commit the UserTransaction\n    }\n    // never blind-retry commit(): initiator was already cleared\n}","preventionTips":["Do not swallow exceptions inside bean-managed transactions","Ensure the EE context permits BMT commit (SecurityException causes)","Set UT/TM timeouts so the transaction is still alive at commit time"],"tags":["jta","transactions","hibernate","usertransaction","commit","rollback-only"],"backgroundTag":"transaction-commit-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}