{"record":{"id":"8ac8ac554087dc7b","repo":"mybatis/mybatis-3","slug":"error-configuring-autocommit-your-driver-may-not","errorCode":null,"errorMessage":"Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: \" + desiredAutoCommit + \".  Cause: \" + e","messagePattern":"Error configuring AutoCommit\\.  Your driver may not support getAutoCommit\\(\\) or setAutoCommit\\(\\)\\. Requested setting: \" \\+ desiredAutoCommit \\+ \"\\.  Cause: \" \\+ e","errorType":"exception","errorClass":"TransactionException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java","lineNumber":114,"sourceCode":"      if (log.isDebugEnabled()) {\n        log.debug(\"Closing JDBC Connection [\" + connection + \"]\");\n      }\n      connection.close();\n    }\n  }\n\n  protected void setDesiredAutoCommit(boolean desiredAutoCommit) {\n    try {\n      if (connection.getAutoCommit() != desiredAutoCommit) {\n        if (log.isDebugEnabled()) {\n          log.debug(\"Setting autocommit to \" + desiredAutoCommit + \" on JDBC Connection [\" + connection + \"]\");\n        }\n        connection.setAutoCommit(desiredAutoCommit);\n      }\n    } catch (SQLException e) {\n      // Only a very poorly implemented driver would fail here,\n      // and there's not much we can do about that.\n      throw new TransactionException(\n          \"Error configuring AutoCommit.  \" + \"Your driver may not support getAutoCommit() or setAutoCommit(). \"\n              + \"Requested setting: \" + desiredAutoCommit + \".  Cause: \" + e,\n          e);\n    }\n  }\n\n  protected void resetAutoCommit() {\n    try {\n      if (!skipSetAutoCommitOnClose && !connection.getAutoCommit()) {\n        // MyBatis does not call commit/rollback on a connection if just selects were performed.\n        // Some databases start transactions with select statements\n        // and they mandate a commit/rollback before closing the connection.\n        // A workaround is setting the autocommit to true before closing the connection.\n        // Sybase throws an exception here.\n        if (log.isDebugEnabled()) {\n          log.debug(\"Resetting autocommit to true on JDBC Connection [\" + connection + \"]\");\n        }\n        connection.setAutoCommit(true);","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java#L96-L132","documentation":"JdbcTransaction.setDesiredAutoCommit() compares connection.getAutoCommit() with the desired setting and calls setAutoCommit() when they differ; any SQLException from either driver call is wrapped in TransactionException stating the driver may not support getAutoCommit()/setAutoCommit() and echoing the requested value. The comment in code acknowledges only a poorly implemented driver fails here — in practice the root cause is usually the driver/database refusing the operation in the connection's current state.","triggerScenarios":"Opening a session (or first statement / commit boundary) with a driver that disallows autoCommit changes mid-transaction; connections handed out inside an XA/distributed transaction where the transaction manager owns autoCommit; a pool (e.g. certain app-managed pools) that already closed or invalidated the connection; older/limited JDBC drivers for niche databases lacking setAutoCommit support.","commonSituations":"Switching to an XA datasource or JTA transaction manager while MyBatis still uses JdbcTransactionFactory (use ManagedTransactionFactory instead); database-side restrictions (some analytic/warehouse DBs reject setAutoCommit(false)); connection pool misconfiguration returning broken connections; driver version downgrade.","solutions":["Under JTA/managed transactions, configure <transactionManager type=\"MANAGED\"/> (ManagedTransactionFactory, or Spring's managed factory) so MyBatis never touches autoCommit.","Upgrade or replace the JDBC driver with one that fully implements getAutoCommit/setAutoCommit.","Ensure sessions set autoCommit only at clean connection boundaries: open the session before any statement runs, avoid toggling autoCommit mid-transaction via setAutoCommit on the SqlSession.","If the database genuinely forbids setAutoCommit(false), keep autoCommit true and rely on per-statement semantics or the database's own transaction controls."],"exampleFix":"// before (mybatis-config.xml)\n<environments default=\"dev\">\n  <environment id=\"dev\">\n    <transactionManager type=\"JDBC\"/>\n    <dataSource type=\"JNDI\">...</dataSource>\n  </environment>\n</environments>\n// after (container/JTA-managed connections)\n<transactionManager type=\"MANAGED\"/>\n<dataSource type=\"JNDI\">...</dataSource>","handlingStrategy":"try-catch","validationCode":"// Probe driver capability once at startup\ntry (Connection c = dataSource.getConnection()) {\n  boolean ac = c.getAutoCommit();\n  c.setAutoCommit(!ac);\n  c.setAutoCommit(ac);\n} catch (SQLException e) {\n  throw new IllegalStateException(\"Driver/datasource does not allow autoCommit control; use MANAGED transaction manager\", e);\n}","typeGuard":null,"tryCatchPattern":"try (SqlSession s = factory.openSession()) { /* work */ }\ncatch (TransactionException e) { /* 'Error configuring AutoCommit' -> switch to ManagedTransactionFactory or fix driver/pool */ throw e; }","preventionTips":["Use type=\"MANAGED\" transaction manager whenever a container/JTA/pool controls transactions.","Keep the JDBC driver current; full getAutoCommit/setAutoCommit support is required by JDBC.","Never toggle autoCommit mid-transaction; set the desired mode at session open."],"tags":["mybatis","transaction","jdbc","driver","autocommit"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}