Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 3279B9FB4B5 for ; Sat, 16 Jun 2007 11:16:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 01345-10 for ; Sat, 16 Jun 2007 11:16:13 -0300 (ADT) X-Greylist: delayed 00:08:23.987316 by SQLgrey-1.7.4 Received: from smtp4.libero.it (smtp4.libero.it [193.70.192.54]) by postgresql.org (Postfix) with ESMTP id 903C29FB37F for ; Sat, 16 Jun 2007 11:16:19 -0300 (ADT) Received: from smtp-out1.libero.it (192.168.32.25) by smtp4.libero.it (7.2.079) id 45AEB96703990775 for pgsql-jdbc@postgresql.org; Sat, 16 Jun 2007 16:07:54 +0200 Received: from outrelay08.libero.it (172.31.0.124) by smtp-out1.libero.it (7.3.120) id 4611FD1805098959 for pgsql-jdbc@postgresql.org; Sat, 16 Jun 2007 16:07:54 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AswMAN2Kc0aXJeMQdGdsb2JhbACMSYJtATc Received: from adsl-16-227.37-151.net24.it (HELO fluca.local) ([151.37.227.16]) by outrelay08.libero.it with ESMTP; 16 Jun 2007 16:07:53 +0200 From: Luca Ferrari To: pgsql-jdbc@postgresql.org Subject: a simple example of XA (not working) Date: Sat, 16 Jun 2007 16:07:52 +0200 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706161607.52540.fluca1978@infinito.it> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200706/50 X-Sequence-Number: 17112 Hi all, I'm trying to build a simple "manual" example of the use of the XA extensio= n,=20 the following is the code: PGXADataSource dataSource =3D new PGXADataSource(); dataSource.setDatabaseName("hrpm"); =09 dataSource.setUser("luca"); =09 dataSource.setServerName("localhost"); =09 =09 XAConnection connection =3D dataSource.getXAConnection(); System.out.println("Connesso!"); XAResource resource =3D connection.getXAResource(); MyXid identifier =3D new MyXid(); identifier.setBranchQualifier(new byte[] {0x01, 0x02, 0x03, 0x04, 0x05}); identifier.setGlobalTransactionId(new byte[] {0x05, 0x04, 0x03, 0x02, 0x01= }); identifier.setFormatId(100); =09 try{ resource.start(identifier, XAResource.TMNOFLAGS); =20 =20 Connection jdbcConnection =3D connection.getConnection(); Statement statement =3D jdbcConnection.createStatement(); String sql =3D "INSERT INTO ..."; int inserted =3D statement.executeUpdate(sql); resource.end(identifier, XAResource.TMSUCCESS); =20 int commit =3D resource.prepare(identifier);=20 if( commit =3D=3D XAResource.XA_OK ) resource.commit(identifier, false); else resource.rollback(identifier); now the exception that is raised when the program commits the transaction i= s=20 the following: javax.transaction.xa.XAException: org.postgresql.util.PSQLException: ERROR:= =20 prepared transaction with identifier "100_BQQDAgE=3D_AQIDBAU=3D" does not e= xist 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 : INSERT INTO .... 2007-06-16 16:05:48 CEST LOG: execute : PREPARE=20 TRANSACTION '100_BQQDAgE=3D_AQIDBAU=3D' 2007-06-16 16:05:48 CEST WARNING: non c'=E8 nessuna transazione in corso 2007-06-16 16:05:48 CEST LOG: execute : COMMIT=20 PREPARED '100_BQQDAgE=3D_AQIDBAU=3D' 2007-06-16 16:05:48 CEST ERROR: prepared transaction with=20 identifier "100_BQQDAgE=3D_AQIDBAU=3D" does not exist 2007-06-16 16:05:48 CEST STATEMENT: COMMIT PREPARED '100_BQQDAgE=3D_AQIDBA= U=3D' 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. Howeve= r,=20 debugging the application, I've seen that the driver disables the autocommi= t=20 mode, thus where is the problem here? I'm sorry, I'm not a XA expert, just learning. Thanks, Luca