JDBC could not be executed by calling commit when autocommit = true. Does a multi-user hibernation session somehow change the auto message?

I have a main thread that spawns thread # 2, which uses the same hibernation session in the main thread. Theme # 2 just β€œpicks 1” every few minutes to maintain a db connection due to the long process from the main thread. As soon as the main thread is executed with processing, it causes a commit, but I get an error:

Caused by: org.hibernate.TransactionException: JDBC commit failed at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:161) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655) ... 5 more Caused by: java.sql.SQLException: Can't call commit when autocommit=true at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:930) at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1602) at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146) ... 6 more 

In the main thread, it creates internal transactions that are completed successfully, it is just an external transaction when it commits an error that causes this error. I do not see what can be changed using autocommit boolean. Before I introduced the second thread to keep in touch, this error never occurred.

+8
spring multithreading hibernate session
source share
2 answers

Even if I think you should seriously reconsider the way you use Hibernate, you can work around this problem by adding the relaxAutoCommit parameter to the JDBC driver in your URL.

http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

+5
source share

found the answer in the blog , the solution quotes:

Setting the relaxAutoCommit = true attribute in the jdbc url we solved our problem.

 jdbc:mysql://dbserver/database?rewriteBatchedStatements=true&relaxAutoCommit=true 

Of course, the blog is in a different scenario, just skip the "rewriteBatchedStatements = true" part

+3
source share

All Articles