mybatis/mybatis-3 · error · TransactionException
Error configuring AutoCommit. Your driver may not support g
Error message
Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: " + desiredAutoCommit + ". Cause: " + e
What it means
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.
Source
Thrown at src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java:114
if (log.isDebugEnabled()) {
log.debug("Closing JDBC Connection [" + connection + "]");
}
connection.close();
}
}
protected void setDesiredAutoCommit(boolean desiredAutoCommit) {
try {
if (connection.getAutoCommit() != desiredAutoCommit) {
if (log.isDebugEnabled()) {
log.debug("Setting autocommit to " + desiredAutoCommit + " on JDBC Connection [" + connection + "]");
}
connection.setAutoCommit(desiredAutoCommit);
}
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException(
"Error configuring AutoCommit. " + "Your driver may not support getAutoCommit() or setAutoCommit(). "
+ "Requested setting: " + desiredAutoCommit + ". Cause: " + e,
e);
}
}
protected void resetAutoCommit() {
try {
if (!skipSetAutoCommitOnClose && !connection.getAutoCommit()) {
// MyBatis does not call commit/rollback on a connection if just selects were performed.
// Some databases start transactions with select statements
// and they mandate a commit/rollback before closing the connection.
// A workaround is setting the autocommit to true before closing the connection.
// Sybase throws an exception here.
if (log.isDebugEnabled()) {
log.debug("Resetting autocommit to true on JDBC Connection [" + connection + "]");
}
connection.setAutoCommit(true);View on GitHub (pinned to 008069adb1)
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.
Example fix
// before (mybatis-config.xml)
<environments default="dev">
<environment id="dev">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">...</dataSource>
</environment>
</environments>
// after (container/JTA-managed connections)
<transactionManager type="MANAGED"/>
<dataSource type="JNDI">...</dataSource> Defensive patterns
Strategy: try-catch
Validate before calling
// Probe driver capability once at startup
try (Connection c = dataSource.getConnection()) {
boolean ac = c.getAutoCommit();
c.setAutoCommit(!ac);
c.setAutoCommit(ac);
} catch (SQLException e) {
throw new IllegalStateException("Driver/datasource does not allow autoCommit control; use MANAGED transaction manager", e);
} Try / catch
try (SqlSession s = factory.openSession()) { /* work */ }
catch (TransactionException e) { /* 'Error configuring AutoCommit' -> switch to ManagedTransactionFactory or fix driver/pool */ throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not set AutoCommit to {}. Cause: {}
- Error accessing PooledConnection. Connection is invalid.
- Cannot commit, transaction is already closed
- Error getting constructor collection nested result map value
- Error getting nested result map values for '{}'. Cause: {}
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/8ac8ac554087dc7b.
Report an issue: GitHub.