{"record":{"id":"2ff93e54c81d4f78","repo":"hibernate/hibernate-orm","slug":"jta-transactionmanager-begin-failed","errorCode":null,"errorMessage":"JTA TransactionManager.begin() failed","messagePattern":"JTA TransactionManager\\.begin\\(\\) failed","errorType":"exception","errorClass":"TransactionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionAdapterTransactionManagerImpl.java","lineNumber":45,"sourceCode":"\tpublic JtaTransactionAdapterTransactionManagerImpl(@Nonnull TransactionManager transactionManager) {\n\t\tthis.transactionManager = transactionManager;\n\t}\n\n\t@Override\n\tpublic void begin() {\n\t\ttry {\n\t\t\tif ( getStatus() == TransactionStatus.NOT_ACTIVE ) {\n\t\t\t\tJTA_LOGGER.callingTransactionManagerBegin();\n\t\t\t\ttransactionManager.begin();\n\t\t\t\tinitiator = true;\n\t\t\t\tJTA_LOGGER.calledTransactionManagerBegin();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tJTA_LOGGER.skippingTransactionManagerBegin();\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new TransactionException( \"JTA TransactionManager.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.callingTransactionManagerCommit();\n\t\t\t\ttransactionManager.commit();\n\t\t\t\tJTA_LOGGER.calledTransactionManagerCommit();\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 TransactionManager.commit() failed\", e );","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionAdapterTransactionManagerImpl.java#L27-L63","documentation":"JtaTransactionAdapterTransactionManagerImpl.begin() calls TransactionManager.begin() only when it just observed status NOT_ACTIVE, and wraps any exception in this TransactionException, surfaced by Session.beginTransaction()/Transaction.begin() on a JTA coordinator. Either the status snapshot raced (a JTA transaction became associated between the getStatus() check and begin()) or the TransactionManager itself failed to begin (NotSupportedException/SystemException/IllegalStateException).","triggerScenarios":"session.beginTransaction() when a JTA transaction is already on the thread (container-managed transaction active, or a stale transaction left by thread-pool reuse), or the TM throws from begin() - TM stopped, nested begin unsupported, or internal error.","commonSituations":"Mixing manual Transaction.begin() with container-managed transactions on the same threads; pooled threads not cleaned after an incomplete transaction; a wrong JtaPlatform resolving a dead TransactionManager; SE setups where the TM was never started.","solutions":["Prefer container/Spring-managed transaction demarcation on JTA deployments and drop manual beginTransaction() calls","Check status first and only begin when it is NOT_ACTIVE: session.getTransaction().getStatus()","Verify hibernate.transaction.jta.platform resolves the container's real TransactionManager","Restart or recover the TransactionManager if it reports SystemException"],"exampleFix":"// before\nSession s = sf.openSession();\ns.beginTransaction(); // races an already-active JTA transaction\n\n// after\nif ( s.getTransaction().getStatus() == TransactionStatus.NOT_ACTIVE ) {\n    s.beginTransaction();\n}","handlingStrategy":"validation","validationCode":"// Only begin when Hibernate sees no active transaction\nif ( session.getTransaction().getStatus() == TransactionStatus.NOT_ACTIVE ) {\n    session.beginTransaction();\n}\nelse {\n    throw new IllegalStateException(\"A JTA transaction is already active; join it instead of beginning\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    session.beginTransaction();\n}\ncatch (TransactionException e) {\n    Throwable c = e.getCause();\n    if ( c instanceof IllegalStateException || c instanceof NotSupportedException ) {\n        // a JTA transaction is already associated with this thread\n    }\n    throw e;\n}","preventionTips":["Do not call beginTransaction() on threads that may already carry a container-managed JTA transaction","Clean thread-bound transactions when using custom thread pools","Validate the JTA platform wiring at startup with a smoke-test transaction"],"tags":["jta","transactions","hibernate","begin"],"backgroundTag":"transaction-begin-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}