From: Heikki Linnakangas <heikki@enterprisedb.com>
To: Allan Saddi <allan@saddi.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: XA transactions and autocommit
Date: Mon, 09 Oct 2006 11:36:11 +0100
Message-ID: <452A261B.6030501@enterprisedb.com> (raw)
In-Reply-To: <4EA0BEEF-A4F2-43CD-82A3-C8888155E06E@saddi.com>
References: <4EA0BEEF-A4F2-43CD-82A3-C8888155E06E@saddi.com>
Allan Saddi wrote:
>
> I've been playing around with JTA using Apache Geronimo and the
> postgresql-8.1-407.jdbc3.jar driver. I've noticed a minor problem. The
> driver's XA code disables autocommit and assumes it will remain so
> indefinitely. tranql-connection (used by Geronimo for pooling) enables
> autocommit whenever the connection is returned to the pool.
> (Specifically in its ManagedXAConnection.cleanup method.) According to
> the J2EE Connector spec, this is apparently the correct thing to do.
Specifically, the spec says that:
A resource adapter must manage the auto-commit mode as follows:
* A transactional resource adapter, either at XATransaction or
LocalTransaction level, must set the auto-commit mode to false within
transaction, either local or XA, on a connection participating in the
transaction.
This requirement holds for both container-managed and bean-managed
transaction demarcation.
* A transactional resource adapter must set the auto-commit mode to
true, on connections that are used outside a transaction.
What's the resource adapter in this scenario? Is it the PostgreSQL JDBC
driver or TranQL? If it's TranQL, then it's not properly calling
setAutoCommit(false) when the connection is used in a global
transaction. If it's the JDBC driver, then we're not doing our job
properly, but then TranQL shouldn't be messing with setAutoCommit in the
first place.
> I didn't notice the problem until I tried rolling back a transaction,
> where I discovered it was being committed instead. Eventually I traced
> it to the fact that autocommit was on.
>
> Arguably, if you follow what the connector spec has to say about
> autocommit and XA transactions, autocommit should be on by default and
> should only be explicitly disabled during the duration of a transaction.
Yeah, I agree that's what we should do. Even if the spec isn't 100%
clear on this, it looks like the safest thing to do. Furthermore, we
should probably throw an exception if you try to set auto commit to true
within a global transaction.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: heikki@enterprisedb.com, allan@saddi.com
Subject: Re: XA transactions and autocommit
In-Reply-To: <452A261B.6030501@enterprisedb.com>
References: <4EA0BEEF-A4F2-43CD-82A3-C8888155E06E@saddi.com> <452A261B.6030501@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox