From: Luca Ferrari <fluca1978@infinito.it>
To: pgsql-jdbc@postgresql.org
Subject: a simple example of XA (not working)
Date: Sat, 16 Jun 2007 16:07:52 +0200
Message-ID: <200706161607.52540.fluca1978@infinito.it> (raw)
Hi all,
I'm trying to build a simple "manual" example of the use of the XA extension,
the following is the code:
PGXADataSource dataSource = new PGXADataSource();
dataSource.setDatabaseName("hrpm");
dataSource.setUser("luca");
dataSource.setServerName("localhost");
XAConnection connection = dataSource.getXAConnection();
System.out.println("Connesso!");
XAResource resource = connection.getXAResource();
MyXid identifier = new MyXid();
identifier.setBranchQualifier(new byte[] {0x01, 0x02, 0x03, 0x04, 0x05});
identifier.setGlobalTransactionId(new byte[] {0x05, 0x04, 0x03, 0x02, 0x01});
identifier.setFormatId(100);
try{
resource.start(identifier, XAResource.TMNOFLAGS);
Connection jdbcConnection = connection.getConnection();
Statement statement = jdbcConnection.createStatement();
String sql = "INSERT INTO ...";
int inserted = statement.executeUpdate(sql);
resource.end(identifier, XAResource.TMSUCCESS);
int commit = resource.prepare(identifier);
if( commit == XAResource.XA_OK )
resource.commit(identifier, false);
else
resource.rollback(identifier);
now the exception that is raised when the program commits the transaction is
the following:
javax.transaction.xa.XAException: org.postgresql.util.PSQLException: ERROR:
prepared transaction with identifier "100_BQQDAgE=_AQIDBAU=" does not exist
at org.postgresql.xa.PGXAConnection.commitPrepared(PGXAConnection.java:412)
at org.postgresql.xa.PGXAConnection.commit(PGXAConnection.java:339)
and the log of the database says:
2007-06-16 16:05:48 CEST LOG: execute <unnamed>: INSERT INTO ....
2007-06-16 16:05:48 CEST LOG: execute <unnamed>: PREPARE
TRANSACTION '100_BQQDAgE=_AQIDBAU='
2007-06-16 16:05:48 CEST WARNING: non c'รจ nessuna transazione in corso
2007-06-16 16:05:48 CEST LOG: execute <unnamed>: COMMIT
PREPARED '100_BQQDAgE=_AQIDBAU='
2007-06-16 16:05:48 CEST ERROR: prepared transaction with
identifier "100_BQQDAgE=_AQIDBAU=" does not exist
2007-06-16 16:05:48 CEST STATEMENT: COMMIT PREPARED '100_BQQDAgE=_AQIDBAU='
2007-06-16 16:05:49 CEST LOG: unexpected EOF on client connection
that is an error since it seems no one transaction has been started. However,
debugging the application, I've seen that the driver disables the autocommit
mode, thus where is the problem here?
I'm sorry, I'm not a XA expert, just learning.
Thanks,
Luca
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: fluca1978@infinito.it
Subject: Re: a simple example of XA (not working)
In-Reply-To: <200706161607.52540.fluca1978@infinito.it>
References: <200706161607.52540.fluca1978@infinito.it>
* 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