-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow skipping setAutoCommit() call in JdbcTransaction #2426
Comments
SET AUTOCOMMIT is causing peformance hit in our case. |
please use regular pooled data source. We used mysql. with resetAutoCommit() without resetAutoCommit() It's 10% diffrence in our test environment. |
Hi @katsumiy , I'm sorry about the belated reply. This is about mybatis-3/src/main/java/org/apache/ibatis/transaction/jdbc/JdbcTransaction.java Lines 117 to 121 in 395be63
So, The sample code you posted opens a new session for each execution. |
ummm, I think using AutoCommit to commit/rollback active transaction is not good idea. also when connection is returned to pool, active transaction should be rolled back not commited. And if this is work around for Sybase JDBC driver, I think we should have code only for Sybase. Causing performance hit just to work around unknown version and not widely used Sybase driver is not good option. Do we know which version of Sybase driver cause exception? Have we tried latest driver? The sample code is reduced pseudo code. The DB access code in real code are spread wide and called so often. So session can't be combined. As you can see below bug for commons DBCP, they have same problem and they put new parameter to disable setting and resettiing auto commit for each borrow. |
As stated in the comment, MyBatis does not call commit/rollback on a connection if just selects were performed. And the reason why it calls I'm open to suggestions, but the new solution 1) must not call Alternatively, you can copy and modify the built-in |
Sample configuration: ```xml <transactionManager type="JDBC"> <property name="skipSetAutoCommitOnClose" value="true"/> </transactionManager> ``` - Enabling this switch skips `setAutoCommit(true)` call when closing the transaction. - Enabling this switch may improve performance with some drivers (e.g. mysql-connector-java, mssql-jdbc), but not others (e.g. Oracle). - Enabling this switch may cause exception with some drivers (e.g. Derby). Should fix mybatis#2426 TODO: docs
Yes, this definitely fix our issue. Please proceed releasing. |
@katsumiy , |
Why resetAutoCommit() in close is necessary?
When connection is newly created or popped from pool, setDesiredAutoCommit is called and AutoCommit is set to desired state, anyway.
When connection is not pooled and really closed, resetting AutoCommit appears to be useless. Because it's going to be closed.
So in both pooled and non pooled case, resetAutoCommit appears to be useless.
And setting when popped and resetting when pushed, it exec “SET AUTOCOMMIT” and it’s taking some time to process.
Shouldn't resetAutoCommit in close be removed?
The text was updated successfully, but these errors were encountered: