Re: Bug: Transaction still open after error when autocommit=true

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Daniel Migowski <dmigowski(at)ikoffice(dot)de>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Bug: Transaction still open after error when autocommit=true
Date: 2011-12-23 01:56:49
Message-ID: CA+0W9LM4sPezbSQ2t1RukzFFapksLyJsqYw0aw-Z16SOd92tqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 23 December 2011 10:09, Daniel Migowski <dmigowski(at)ikoffice(dot)de> wrote:

> If I send a statement with a BEGIN token

Don't do that; the driver is expecting you to manage transaction
demarcation by using JDBC's autocommit setting and commit/rollback,
not by sending explicit SQL. (Kevin pointed out the relevant JDBC
javadoc that covers this in his reply)

If you must send a raw BEGIN for some reason, then you're also
responsible for transaction cleanup yourself (i.e. don't expect
commit() or rollback() to work; you must send appropriate SQL yourself
to commit or rollback the transaction)

The driver's implementation of autocommit boils down to "if autocommit
is off and the connection does not have an active transaction, then
send BEGIN before the next query". When autocommit is on, the driver
just assumes the server's default behavior - i.e. autocommit happens
without any special intervention. If you send an explicit transaction
demarcation commands, you'll confuse that.

Oliver

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Magosányi Árpád 2011-12-23 15:12:58 Datasource portNumber property
Previous Message Dave Cramer 2011-12-23 01:00:07 Re: Bug: Transaction still open after error when autocommit=true