pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
use of savepoint in containter managed transaction
7+ messages / 4 participants
[nested] [flat]

* use of savepoint in containter managed transaction
@ 2011-09-23 06:31  Amar Dhole <adhole@tibco.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Amar Dhole @ 2011-09-23 06:31 UTC (permalink / raw)
  To: pgsql-jdbc

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 ?
2) Can I make some custom change to jdbc driver to ignore duplicate key exception or to raise warning instead ERROR.

Thanks
Amar 



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-23 11:54  Radosław Smogura <rsmogura@softperience.eu>
  parent: Amar Dhole <adhole@tibco.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Radosław Smogura @ 2011-09-23 11:54 UTC (permalink / raw)
  To: Amar Dhole <adhole@tibco.com>; +Cc: pgsql-jdbc

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-23 12:38  Andrew Hastie <andrew@ahastie.net>
  parent: Radosław Smogura <rsmogura@softperience.eu>
  1 sibling, 0 replies; 7+ messages in thread

From: Andrew Hastie @ 2011-09-23 12:38 UTC (permalink / raw)
  To: pgsql-jdbc

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
>



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-23 13:19  Amar Dhole <adhole@tibco.com>
  parent: Radosław Smogura <rsmogura@softperience.eu>
  1 sibling, 1 reply; 7+ messages in thread

From: Amar Dhole @ 2011-09-23 13:19 UTC (permalink / raw)
  To: 'rsmogura@softperience.eu' <rsmogura@softperience.eu>; +Cc: pgsql-jdbc

Hi,

I have tried to use savepoint in jboss I got exception ,
"Since it is managed transaction rollback not allowed"
It will be great help how to avoid this error.

2) I have session bean where my transaction started it has assume 20 insert in one table at 10th insert I get duplicate key exception what we do in our application increase key by catching exception and proceed ahead by in postgress when this exception occurs my all insert gets error out. So I thought to use savepoint or any other way to avoid this exception and proceed in my transaction.

Thanks,
Amar

----- Original Message -----
From: Radosław Smogura [mailto:rsmogura@softperience.eu]
Sent: Friday, September 23, 2011 04:54 AM
To: Amar Dhole
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: [JDBC] use of savepoint in containter managed transaction

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


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-23 13:58  Radosław Smogura <rsmogura@softperience.eu>
  parent: Amar Dhole <adhole@tibco.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Radosław Smogura @ 2011-09-23 13:58 UTC (permalink / raw)
  To: Amar Dhole <adhole@tibco.com>; +Cc: pgsql-jdbc

I may suggest You, to try to manually use savepoints and rollbacks by 
explicite specifying such queryies

createStatemnet().executeUpdate("SAVEPOINT ...")
createStatemnet().executeUpdate(ROLLBACK TO SAVEPOINT....)
createStatemnet().executeUpdate(RELEASE SAVEPOINT....)
but do not use COMMIT, nor ROLLBACK, nor PREPARE TRANSACTION.

You will need to put some work to arm your code in necessary try/catch.

If this will work, and consequences of this I don't know (I suppose at 
80-90% that this should not affect XA, it's really hard to tell at eye 
glance).

To your 1st topic
"Since it is managed transaction rollback not allowed" I couldn't find 
itin JDBC source code, so I assume, JBoss wrapped driver. PG driver will 
prohibit this behaviour too, but with different message.

Regards,
Radosław Smogura
http://softperience.eu

On Fri, 23 Sep 2011 13:19:53 +0000, Amar Dhole wrote:
> Hi,
>
> I have tried to use savepoint in jboss I got exception ,
> "Since it is managed transaction rollback not allowed"
> It will be great help how to avoid this error.
>
> 2) I have session bean where my transaction started it has assume 20
> insert in one table at 10th insert I get duplicate key exception what
> we do in our application increase key by catching exception and
> proceed ahead by in postgress when this exception occurs my all 
> insert
> gets error out. So I thought to use savepoint or any other way to
> avoid this exception and proceed in my transaction.
>
> Thanks,
> Amar
>
> ----- Original Message -----
> From: Radosław Smogura [mailto:rsmogura@softperience.eu]
> Sent: Friday, September 23, 2011 04:54 AM
> To: Amar Dhole
> Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
> Subject: Re: [JDBC] use of savepoint in containter managed 
> transaction
>
> 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




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-23 18:31  Amar Dhole <adhole@tibco.com>
  parent: Radosław Smogura <rsmogura@softperience.eu>
  1 sibling, 0 replies; 7+ messages in thread

From: Amar Dhole @ 2011-09-23 18:31 UTC (permalink / raw)
  To: Radosław Smogura <rsmogura@softperience.eu>; +Cc: pgsql-jdbc

Hi Radosław,

This approach works fine. 
Thanks for your valuable inputs.

Thanks
Amar 

-----Original Message-----
From: Radosław Smogura [mailto:rsmogura@softperience.eu] 
Sent: 23 September 2011 19:29
To: Amar Dhole
Cc: 'pgsql-jdbc@postgresql.org'
Subject: Re: [JDBC] use of savepoint in containter managed transaction

I may suggest You, to try to manually use savepoints and rollbacks by 
explicite specifying such queryies

createStatemnet().executeUpdate("SAVEPOINT ...")
createStatemnet().executeUpdate(ROLLBACK TO SAVEPOINT....)
createStatemnet().executeUpdate(RELEASE SAVEPOINT....)
but do not use COMMIT, nor ROLLBACK, nor PREPARE TRANSACTION.

You will need to put some work to arm your code in necessary try/catch.

If this will work, and consequences of this I don't know (I suppose at 
80-90% that this should not affect XA, it's really hard to tell at eye 
glance).

To your 1st topic
"Since it is managed transaction rollback not allowed" I couldn't find 
itin JDBC source code, so I assume, JBoss wrapped driver. PG driver will 
prohibit this behaviour too, but with different message.

Regards,
Radosław Smogura
http://softperience.eu

On Fri, 23 Sep 2011 13:19:53 +0000, Amar Dhole wrote:
> Hi,
>
> I have tried to use savepoint in jboss I got exception ,
> "Since it is managed transaction rollback not allowed"
> It will be great help how to avoid this error.
>
> 2) I have session bean where my transaction started it has assume 20
> insert in one table at 10th insert I get duplicate key exception what
> we do in our application increase key by catching exception and
> proceed ahead by in postgress when this exception occurs my all 
> insert
> gets error out. So I thought to use savepoint or any other way to
> avoid this exception and proceed in my transaction.
>
> Thanks,
> Amar
>
> ----- Original Message -----
> From: Radosław Smogura [mailto:rsmogura@softperience.eu]
> Sent: Friday, September 23, 2011 04:54 AM
> To: Amar Dhole
> Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
> Subject: Re: [JDBC] use of savepoint in containter managed 
> transaction
>
> 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




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: use of savepoint in containter managed transaction
@ 2011-09-25 11:53  Craig Ringer <ringerc@ringerc.id.au>
  parent: Radosław Smogura <rsmogura@softperience.eu>
  1 sibling, 0 replies; 7+ messages in thread

From: Craig Ringer @ 2011-09-25 11:53 UTC (permalink / raw)
  To: Radosław Smogura <rsmogura@softperience.eu>; +Cc: Amar Dhole <adhole@tibco.com>; pgsql-jdbc

On 23/09/2011 9:58 PM, Radosław Smogura wrote:
> I may suggest You, to try to manually use savepoints and rollbacks by 
> explicite specifying such queryies
>
> createStatemnet().executeUpdate("SAVEPOINT ...")
> createStatemnet().executeUpdate(ROLLBACK TO SAVEPOINT....)
> createStatemnet().executeUpdate(RELEASE SAVEPOINT....)
> but do not use COMMIT, nor ROLLBACK, nor PREPARE TRANSACTION.
>
> You will need to put some work to arm your code in necessary try/catch.
>
> If this will work, and consequences of this I don't know (I suppose at 
> 80-90% that this should not affect XA, it's really hard to tell at eye 
> glance).

Alternately, tell your container you want a non-JTA-managed tansaction 
so you don't need to worry about disturbing its view of the transaction 
state. That's probably safer, since you want to manage your own 
transactions so you don't really want JTA anyway.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2011-09-25 11:53 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-23 06:31 use of savepoint in containter managed transaction Amar Dhole <adhole@tibco.com>
2011-09-23 11:54 ` Radosław Smogura <rsmogura@softperience.eu>
2011-09-23 12:38   ` Andrew Hastie <andrew@ahastie.net>
2011-09-23 13:19   ` Amar Dhole <adhole@tibco.com>
2011-09-23 13:58     ` Radosław Smogura <rsmogura@softperience.eu>
2011-09-23 18:31       ` Amar Dhole <adhole@tibco.com>
2011-09-25 11:53       ` Craig Ringer <ringerc@ringerc.id.au>

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