Spring @Transactional and JDBC autoCommit

前端 未结 1 1656
忘掉有多难
忘掉有多难 2020-12-16 13:56

On my actual application, I have a DBCP connection pool which doesn\'t have JDBC autoCommit=false set. It seems to have the default autoCommit=true. This is probably a mista

相关标签:
1条回答
  • 2020-12-16 14:13

    PlatformTransactionManager is an interface, so I would not blanket say that all implementations set AutoCommit = false, however the most common implementation (DataSourceTransactionManager) does set AutoCommit = false. see code snippet below from the doBegin method:

    if (con.getAutoCommit()) {
                txObject.setMustRestoreAutoCommit(true);
                if (logger.isDebugEnabled()) {
                    logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
                }
                con.setAutoCommit(false);
            }
            txObject.getConnectionHolder().setTransactionActive(true);
    

    Now as you stated, it makes perfect sense to do so or you would not have a rollback segment to activate a rollback on.

    0 讨论(0)
提交回复
热议问题