{"record":{"id":"dc341dcc74442f87","repo":"hibernate/hibernate-orm","slug":"transaction-not-successfully-started","errorCode":null,"errorMessage":"Transaction not successfully started","messagePattern":"Transaction not successfully started","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionImpl.java","lineNumber":88,"sourceCode":"\t\t\tif ( jpaCompliance ) {\n\t\t\t\tthrow new IllegalStateException( \"Transaction already active (in JPA compliant mode)\" );\n\t\t\t}\n\t\t\telse if ( !transactionCoordinator.getTransactionCoordinatorBuilder().isJta() ) {\n\t\t\t\tthrow new IllegalStateException( \"Resource-local transaction already active\" );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tCORE_LOGGER.beginningTransaction();\n\t\t\ttransactionDriverControl.begin();\n\t\t}\n\t}\n\n\t@Override\n\tpublic void commit() {\n\t\t// allow MARKED_ROLLBACK to propagate through to transactionDriverControl\n\t\tif ( !isActive() ) {\n\t\t\t// we have a transaction that is inactive and has not been marked for rollback only\n\t\t\tthrow new IllegalStateException( \"Transaction not successfully started\" );\n\t\t}\n\t\telse {\n\t\t\tCORE_LOGGER.committingTransaction();\n\t\t\ttry {\n\t\t\t\tinternalGetTransactionDriverControl().commit();\n\t\t\t}\n\t\t\tcatch (RuntimeException e) {\n\t\t\t\tthrow session.getExceptionConverter().convertCommitException( e );\n\t\t\t}\n\t\t}\n\t}\n\n\t@Nonnull\n\tpublic TransactionDriver internalGetTransactionDriverControl() {\n\t\t// NOTE here to help be a more descriptive NullPointerException\n\t\tif ( transactionDriverControl == null ) {\n\t\t\tthrow new IllegalStateException( \"Transaction was not properly begun/started\" );\n\t\t}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionImpl.java#L70-L106","documentation":"TransactionImpl.commit() requires the transaction to be active (or at least marked rollback-only) so commit has something to drive. If the transaction was never begun — or already completed and not marked for rollback — the inactive state means there is nothing to commit, and Hibernate throws IllegalStateException('Transaction not successfully started') instead of performing a silent no-op.","triggerScenarios":"tx.commit() without any tx.begin() (e.g. a Transaction reference obtained via em.getTransaction() but never begun); commit() after an earlier commit()/rollback() already completed the transaction; commit attempted when the driver control was never started.","commonSituations":"finally blocks that commit unconditionally even when begin() failed or was skipped; retry logic that commits twice; code paths where an exception happens before begin() but the catch/finally still commits; tests that forget begin().","solutions":["Guard the commit: if (tx.isActive()) { tx.commit(); } — or only commit in the path where you began it","Structure try/finally so begin() happens before the try, and commit/rollback are mutually exclusive in finally","On business exceptions call rollback() (or markRollbackOnly) instead of letting a commit be reached"],"exampleFix":"// before\nTransaction tx = em.getTransaction();\ntry {\n    doWork();\n} finally {\n    tx.commit(); // never begun / already done -> IllegalStateException\n}\n\n// after\nTransaction tx = em.getTransaction();\ntx.begin();\ntry {\n    doWork();\n    tx.commit();\n} catch (RuntimeException e) {\n    if (tx.isActive()) {\n        tx.rollback();\n    }\n    throw e;\n}","handlingStrategy":"validation","validationCode":"if (tx.isActive()) {\n    tx.commit();\n} else {\n    log.warn(\"Skipping commit: transaction was never begun or already completed\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit only on the path that began the transaction","Track begun-state in a local variable or use try/finally with mutually exclusive commit/rollback","Mark rollback-only instead of committing when prerequisites failed"],"tags":["hibernate","transaction","commit","not-started","lifecycle"],"backgroundTag":"transaction-not-started","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}