pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Hastie <andrew@ahastie.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: use of savepoint in containter managed transaction
Date: Fri, 23 Sep 2011 13:38:48 +0100
Message-ID: <4E7C7DD8.60600@ahastie.net> (raw)
In-Reply-To: <8469d513dfc612cf33aec0c5253f57fe@mail.softperience.eu>
References: <C7BBBF767EA7F7458E9537859DB4FBFB014A0A@se-ex024.groupinfra.com>
	<C7BBBF767EA7F7458E9537859DB4FBFB014B92@se-ex024.groupinfra.com>
	<4D53A504.1030406@enterprisedb.com>
	<201102101145.10201.achill@matrix.gatewaynet.com>
	<B056671652AA4D418763981054BCEAB4092CCE@PA-MBX04.na.tibco.com>
	<8469d513dfc612cf33aec0c5253f57fe@mail.softperience.eu>

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
>



view thread (7+ messages)  latest in thread

Message-ID: <4E7C7DD8.60600@ahastie.net>
Permalink:  ../4E7C7DD8.60600@ahastie.net/
Also on:    postgresql.org/message-id/4E7C7DD8.60600@ahastie.net

 · 

reply

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: andrew@ahastie.net
  Subject: Re: use of savepoint in containter managed transaction
  In-Reply-To: <4E7C7DD8.60600@ahastie.net>
  References: <C7BBBF767EA7F7458E9537859DB4FBFB014A0A@se-ex024.groupinfra.com> <C7BBBF767EA7F7458E9537859DB4FBFB014B92@se-ex024.groupinfra.com> <4D53A504.1030406@enterprisedb.com> <201102101145.10201.achill@matrix.gatewaynet.com> <B056671652AA4D418763981054BCEAB4092CCE@PA-MBX04.na.tibco.com> <8469d513dfc612cf33aec0c5253f57fe@mail.softperience.eu> <4E7C7DD8.60600@ahastie.net>

* 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