Severe bug in java.sql.Connection.setAutoCommit(boolean) implementation

163 views
Skip to first unread message

Freddi Hinz

unread,
Mar 1, 2012, 4:59:48 PM3/1/12
to h2-da...@googlegroups.com
Hi

I just started using H2 today and noted a severe bug in the java.sql.Connection.setAutoCommit(boolean) implementation.

The SUN/Oracle javadoc for JavaSE 1.5 clearly state "NOTE: If this method is called during a transaction, the transaction is committed."

However, by looking at the source of H2, one can see that its implementation of setAutoCommit() only sets the internal autocommit flag, no check whether a transaction is currently running and no commit is being done.

Obviously, software that relies on this fact is not going to work with H2 (transactions won't be committed and locks will be kept forever, unless the connection is closed). In my case, I have ported a small PostgreSQL based app which stopped working after running on H2 (timeouts, since locks were not released).

Cheers,
 Freddi

Noel Grandin

unread,
Mar 2, 2012, 2:27:48 AM3/2/12
to h2-da...@googlegroups.com, Freddi Hinz
It's a bug, and I'm sure we'll get round to fixing it, but its also dodgy behaviour on the part of an application to be relying on that behaviour.
setAutoCommit() is meant to be called once after a connection is established, and then never again.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/WYIQMsqSpYYJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Freddi Hinz

unread,
Mar 2, 2012, 3:59:41 AM3/2/12
to h2-da...@googlegroups.com, Freddi Hinz
Don't get me wrong, but relying upon a clearly documented feature (in bold!) is certainly not doggy behavior =)

setAutoCommit is certainly not meant to be just called once (just think of connections that are being reused by different pieces of code with different autocommit demands).
After all, that is why the method is there: so that the autocommit behavior is not fixed for the lifetime of the connection.

To be more precise, just in case somebody plans to fix this: please be aware that a solid JDBC driver should be able to cope with any sequence of .commit/.rollback/.setAutoCommit/.setReadOnly calls (and maybe setTransactionIsolation, but then the exact outcome is open to the JDBC implementation, see the javadocs for setTransactionIsolation).

Thanks for eventually having a look at this!
 

Thomas Mueller

unread,
Mar 2, 2012, 11:11:00 AM3/2/12
to h2-da...@googlegroups.com
Hi,

OK, I see H2 doesn't follow the specification in this case. This will
be changed it in the next release, unless there is a major problem.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages