I have a Java app which uses JTA(Apache Geronimo) to manage transactions. The database in use is MySQL. App has a lot of begin and commit methods. However looking at the MySQL general log I could not find a single "Start transaction" query/command. The log is full of SET autocommit=1
and SET autocommit=0
with commit
and rollback
. Due to this, looking at logs I am unable to identify at what point the transaction began. I am not a Java guy and I could not find any helping resource on this either.

- 5,038
- 7
- 39
- 51
-
because the developers did implement it that way.. – user85421 Jul 16 '18 at 12:13
-
@CarlosHeuberger what could be the reason for not using `start transaction` query/command to initiate a transaction? – Kumar Jul 16 '18 at 12:15
-
1ask the developers, how should I (we) know??? This is not the kind of question for Stackoverflow. – user85421 Jul 16 '18 at 12:16
-
Thanks a lot @CarlosHeuberger! – Kumar Jul 16 '18 at 12:18
-
1"set commit = 0" sounds like the beginning of the transaction; commit is clearly the end. You need to pair those up. – duffymo Jul 16 '18 at 12:20
2 Answers
Start transaction and commit statements are used in MySql InnoDB. But In MySQL MyISAM, these commands are not valid so you need to use set autocommit = 0
instead of Start Transaction and set autocommit = 1
in place of commit
;
InnoDB allows both the ways but MyISAM allows only set autocommit. Also, note that these commands perform somewhat similar work but they are not identical. And the use of set autocommit is not recommended in InnoDB.
For more information refer this question in StackOverflow.

- 634
- 7
- 12
MySQL's JDBC driver implements the Java JDBC API. The java.sql.Connection interface does not have a method to start a transaction.
A transaction begins implicitly when you execute an SQL query.
If the driver is in autocommit mode, the transaction is committed automatically once the SQL query finishes.
If the driver is not in autocommit mode, the transaction started by your query remains active until you call Connection.commit()
or Connection.rollback()
.
See also How to start a transaction in JDBC?

- 538,548
- 86
- 673
- 828