{"record":{"id":"2b87aa0fffde35c8","repo":"hibernate/hibernate-orm","slug":"unable-to-start-isolated-transaction","errorCode":null,"errorMessage":"Unable to start isolated transaction","messagePattern":"Unable to start isolated transaction","errorType":"exception","errorClass":"TransactionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaIsolationDelegate.java","lineNumber":159,"sourceCode":"\t\t\tJTA_LOGGER.transactionResumed( surroundingTransaction );\n\t\t}\n\t}\n\n\tprivate Transaction suspend() throws SystemException {\n\t\tfinal var surroundingTransaction = transactionManager.suspend();\n\t\tif ( surroundingTransaction != null ) {\n\t\t\tJTA_LOGGER.transactionSuspended( surroundingTransaction );\n\t\t}\n\t\treturn surroundingTransaction;\n\t}\n\n\tprivate <T> T doInNewTransaction(HibernateCallable<T> callable, TransactionManager transactionManager) {\n\t\ttry {\n\t\t\t// start the new isolated transaction\n\t\t\ttransactionManager.begin();\n\t\t}\n\t\tcatch ( SystemException | NotSupportedException exception ) {\n\t\t\tthrow new TransactionException( \"Unable to start isolated transaction\", exception );\n\t\t}\n\n\t\ttry {\n\t\t\tT result = callable.call();\n\t\t\t// if everything went ok, commit the isolated transaction\n\t\t\ttransactionManager.commit();\n\t\t\treturn result;\n\t\t}\n\t\tcatch ( Exception exception ) { //TODO: should this be Throwable\n\t\t\trollBack( transactionManager, exception );\n\t\t\tif ( exception instanceof HibernateException he ) {\n\t\t\t\tthrow he;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new HibernateException( \"Error performing work\", exception );\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaIsolationDelegate.java#L141-L177","documentation":"Thrown by JtaIsolationDelegate.doInNewTransaction when jakarta.transaction.TransactionManager.begin() throws SystemException or NotSupportedException while starting a separate transaction for Hibernate's isolated work. Isolated work is JDBC work Hibernate must run outside your current transaction (the surrounding JTA transaction is suspended first): typically schema-tool operations or isolated ID generators reached via delegateWork/delegateCallable with transacted=true. The failure is the JTA TransactionManager refusing or failing to begin that new transaction, not your own transaction failing.","triggerScenarios":"IsolationDelegate.delegateWork(work, true) or delegateCallable(callable, true) - e.g., a table/sequence ID generator configured for an isolated connection, or hbm2ddl/schema management running against a JTA-managed DataSource - after JtaIsolationDelegate suspended the current transaction and TransactionManager.begin() threw NotSupportedException (TM will not start another transaction) or SystemException (TM error state).","commonSituations":"Using the JTA DataSource for schema generation or generator value lookups; Narayana/Atomikos TransactionManager not started or in recovery; a TransactionManager that does not support suspend+begin; the isolated operation exceeding transaction timeouts.","solutions":["Enable TRACE logging for org.hibernate.resource.transaction.backend.jta to confirm exactly which isolated operation runs when the error occurs","Give schema tools and isolated ID generators their own non-JTA JDBC connection (separate DataSource or non-JTA connection provider) instead of the JTA one","Verify the TransactionManager is started and supports suspend followed by begin (container TM or Narayana JBossStandaloneJTAManager)","If timeouts trigger it, raise the JTA transaction timeout for the affected subsystem"],"exampleFix":"// before: schema management and generators run through the JTA data source\n<persistence-unit name=\"app\">\n  <jta-data-source>java:/appDS</jta-data-source>\n</persistence-unit>\n\n// after: run schema export on a direct JDBC connection before bootstrap, and use pooled\n// optimizers so generators do not need isolated transactions per value\nnew SchemaExport(metadata).execute(EnumSet.of(TargetType.DATABASE), exportTarget);\n\n@Id\n@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = \"order_seq\")\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\", allocationSize = 50)","handlingStrategy":"try-catch","validationCode":"// Verify the TransactionManager is usable before triggering isolated work\ntry {\n    int st = transactionManager.getStatus();\n    if ( st != jakarta.transaction.Status.STATUS_NO_TRANSACTION ) {\n        throw new IllegalStateException(\"Unexpected JTA status before isolated work: \" + st);\n    }\n}\ncatch (SystemException e) {\n    throw new IllegalStateException(\"TransactionManager unusable for isolated work\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return isolationDelegate.delegateWork(work, true);\n}\ncatch (TransactionException e) {\n    // e.getCause() is NotSupportedException or SystemException from TransactionManager.begin()\n    log.error(\"isolated work could not start a transaction: {}\", e.getCause(), e);\n    throw e;\n}","preventionTips":["Do not point hbm2ddl/schema tools at a JTA-managed DataSource","Prefer pooled sequence/table optimizers (allocationSize > 1) so generators avoid per-value isolated transactions","Keep the TransactionManager (Narayana/Atomikos) started and healthy in SE setups"],"tags":["jta","transactions","hibernate","isolation-delegate","schema-tools","id-generation"],"backgroundTag":"transaction-begin-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}