X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7153411F6B93 for ; Sun, 2 Apr 2006 05:58:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33833-06 for ; Sun, 2 Apr 2006 05:58:57 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.192]) by postgresql.org (Postfix) with ESMTP id 40B9D11F6AE5 for ; Sun, 2 Apr 2006 05:58:55 -0300 (ADT) Received: by xproxy.gmail.com with SMTP id h31so688486wxd for ; Sun, 02 Apr 2006 00:58:55 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rbuC8VGpf+C3+NhHkIRdqRy4RiNwDHU/2A+v034z7M2cnlPDjTqPMehPh4+AOp0f6ihRYDW1RlbAnI5+St/pkPm0tQTH9TxjaHIb5m0yzRSCuEL42wNkMRquccJoBDKVZG18SaTaiYfE+Da0esLigHEam2LupxfoI0wI3SHU3GE= Received: by 10.70.49.6 with SMTP id w6mr2205205wxw; Sun, 02 Apr 2006 00:58:55 -0800 (PST) Received: by 10.70.16.4 with HTTP; Sun, 2 Apr 2006 00:58:55 -0800 (PST) Message-ID: Date: Sun, 2 Apr 2006 10:58:55 +0200 From: "=?ISO-8859-1?Q?Reg=E1sz_Imre?=" To: babu_moshay Subject: Re: 25P02, current transaction is aborted, commands ignored until end of transaction block Cc: pgsql-jdbc@postgresql.org In-Reply-To: <200604020407.JAA21169@WS0005.indiatimes.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <200604020407.JAA21169@WS0005.indiatimes.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200604/5 X-Sequence-Number: 14939 You need use SAVEPOINT in transaction: do { String savepointName =3D "any string"+class.hasCode(); Savepoint savePoint =3D conn.setSavepoint(savepointName); try { stmt.execute(); success =3D true; } catch (SQLException sqle) { conn.rollback(savePoint); } } while (!success); http://www.postgresql.org/docs/8.1/interactive/sql-savepoint.html http://www.postgresql.org/docs/8.1/interactive/sql-rollback-to.html On 4/2/06, babu_moshay wrote: > Deal all, > I am trying to port my application from MySql to PostgreSQL 8.X. It seems= PostgreSQL does not give full control to programmer even when they have op= ted to handle the transaction themselves by setting AUTOCOMMIT=3DFALSE in c= ode. > > > Scenario: > 1.Several records are to be inserted in different tables as a result of t= aking an order via web form. This activity must be atomic i.e it must succe= ed or fail completely. > > 2. Autocommit is set to off before an anonymous transaction is started in= JDBC. > > 3.In one of the inserts we must ignore the failure due to duplicate rows = i.e Error state 23505 and continue with remainder set of inserts. Presence = of duplicate rows will not be treated as an error condition in this context= and system must function normally without aborting the whole transaction (= This is what PostgreSQL is doing currently after first failure I get 25P02 = and all other inserts are ignored completely). I get following error: > > org.postgresql.util.PSQLException: ERROR: current transaction is aborted,= commands ignored until end of transaction block > > Technical details: > I don't think this is specific to hardware/software version I am currentl= y using but giving here for the sake of completeness: > PostgreSQL version tried : 8.1.3 and 8.0, 8.0.1 > JDBC: 8.2dev-501.jdbc3, 8.0-315.jdbc3, 8.1-404.jdbc3 > JDK: 1.4 and 1.5 > OS: Windows XP > > Case: > The general expectation is that when a programmer is setting autocommit e= xplicitly to off then they want to be in control of the transactions and 'T= HEY' should decided when to rollback or commit instead of others. This is t= he case with Oracle, SQL Server and MySQL and I think this is a fair expect= ation. I am sure this is fairly common scenario with people who do frequent= backend coding. > > I went through archives as it seems this was not a problem in version 8.0= .1, unfortunately I have tried with 3 different 8.x.x versions available an= d similarly for JDBC drivers and the problem/condition still exists. > > By looking at the error code 25P02, I feel this may not be treated as pro= blem/error by PostgreSQL community. What is the work-around in such event? > > In my opinion, if there are reasons to throw 25P02 and abort transaction = unilaterally, then there are also good reasons not to abort it and let pro= grammer take the decision. A switching mechanism would have been ideal. > > Any help/suggestion much appreciated!!! > > Best regards, > Amaresh Wakkar > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >