Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 13EAFB5DC29 for ; Fri, 23 Sep 2011 10:20:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65883-03 for ; Fri, 23 Sep 2011 13:20:12 +0000 (UTC) X-Greylist: delayed 00:42:09.936303 by SQLgrey-1.8.0-rc2 Received: from cpanelsmarthost3.zen.co.uk (cpanelsmarthost3.zen.co.uk [82.71.204.227]) by mail.postgresql.org (Postfix) with ESMTP id B7539B5DC1B for ; Fri, 23 Sep 2011 10:20:12 -0300 (ADT) Received: from [88.98.24.71] (helo=shcp03.hosting.zen.net.uk) by cpanelsmarthost3.zen.co.uk with esmtp (Exim 4.72) (envelope-from ) id 1R750z-0003eh-Sd for pgsql-jdbc@postgresql.org; Fri, 23 Sep 2011 12:38:01 +0000 Received: from [212.135.39.5] (helo=[62.185.32.161]) by shcp03.hosting.zen.net.uk with esmtpa (Exim 4.69) (envelope-from ) id 1R750w-0004Fc-22 for pgsql-jdbc@postgresql.org; Fri, 23 Sep 2011 13:37:58 +0100 Message-ID: <4E7C7DD8.60600@ahastie.net> Date: Fri, 23 Sep 2011 13:38:48 +0100 From: Andrew Hastie User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: use of savepoint in containter managed transaction References: <4D53A504.1030406@enterprisedb.com> <201102101145.10201.achill@matrix.gatewaynet.com> <8469d513dfc612cf33aec0c5253f57fe@mail.softperience.eu> In-Reply-To: <8469d513dfc612cf33aec0c5253f57fe@mail.softperience.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - shcp03.hosting.zen.net.uk X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - ahastie.net X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201109/94 X-Sequence-Number: 22212 Agree that raising any form of checked exception in a container managed transaction is simply very bad news. You could try changing over to using bean managed transactions, but this will likely raise other issues in how you application is structured. Surely attempting to insert a record with a duplicate key is bad design? Could you not do something like the following pseudo-code :- ResultSet rs = SELECT * FROM table WHERE pk = 'some_value'; if (rs.next()) { // Exists - go and insert into error table } else { // Doesn't exist - insert in now } rs.close My personal rule for anything JDBC related when running inside a JEE container is "keep it simple and clean". That way you'll avoid numerous problems if you ever have to port your application to another database provider or even different JDBC driver. Andrew On 23/09/11 12:54, Radosław Smogura wrote: > On Fri, 23 Sep 2011 06:31:13 +0000, Amar Dhole wrote: >> HI All, >> >> I have requirement to use save point. But I am using session bean >> whose transaction is managed by container. While executing sql insert >> I got unique key constraint because of this my other command following >> this exception got ignored. I want to continue my transaction even >> after this as we ignore this insert and make an entry in other table >> for this error. And proceed head. with Postgres this is not possible. >> I cant user plsql block as behaviour is spread in all my application. >> Need some suggestion to achieve this with savepoint. >> >> I have some question. >> 1) Can I use savepoint in Container Managed transaction ? > Yes, You can, but I don't know result of this. ;) One day I worked on > couple of patches, maybe I have those somewhere to acquire this what I > assume You want. > >> 2) Can I make some custom change to jdbc driver to ignore duplicate >> key exception or to raise warning instead ERROR. > I assume, You want your transaction to proceed when error will occur. > Yes you can make some change to ignore this, but this will not give > you expected behaviour, because error is generated on server side, and > server will rollback transaction. > > But please specify more details mainly what You want achieve and what > are preconditions. >> Thanks >> Amar > > Regards, > Radosław Smogura > http://softperience.eu >