Should the data source autoobject be set to false?

see comments in spring DataSourceTransactionManager.java, doBegin function:

// Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
// so we don't want to do it unnecessarily (for example if we've explicitly
// configured the connection pool to set it already).
        if (con.getAutoCommit()) {
            txObject.setMustRestoreAutoCommit(true);
            if (logger.isDebugEnabled()) {
                logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
            }
            con.setAutoCommit(false);
        }

In the project I'm working on, autocommit is not configured. This is true by default. We use spring to manage transactions, and all SQL queries are executed in annotated @Transactional functions. Thus, transactions are carried out manually. Each time a transaction starts, the db connection is set to autocommit to false, and after the transaction is completed, autocommit returns to true. A typical workflow would be (at the JDBC level):

  • conn = dataSource.getConnection ();
  • conn.setAutoCommit (false);
  • stmt = conn.createStatement ();
  • stmt.executeQuery (...);
  • conn.commit () / conn.rollback ();
  • conn.setAutoCommit (true);

? datasource autocommit = false ? 2 6.

+4
3

1) autocommit , , , . , , , , autocommit false.

2) ,

a) , , ,    , ,   , autocommit .

b) , .

c) .

EDIT: , , : autocommit = false commit/rollback/etc, , , !

. autoocommit false true .

, datasource autocommit = false, - . , , , , , 99,99%, false.

autocommit true , commit .

, , , , ,

, !

+3

, .

SET autocommit=0;
your code here....
SET autocommit=1;

Update:

@codemania , autocommit , . , , .

, - , ​​ .., , .

0

autocommit true, . - , ( , ), , . autocommit = false, , commit() , , , ( ..).

autocommit true ( ), , , , ( / ), , 't , .

, autocommit = true , ( )

0

Source: https://habr.com/ru/post/1622192/


All Articles