pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Radosław Smogura <rsmogura@softperience.eu>
To: mephysto <mephystoonhell@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Fwd: Postgres JDBC, WS and commit
Date: Wed, 09 May 2012 22:30:41 +0200
Message-ID: <8f62136f2ac19fb44383745705190955@mail.softperience.eu> (raw)
In-Reply-To: <1336590679429-5698263.post@n5.nabble.com>
References: <1336576000350-5697657.post@n5.nabble.com>
	<CAC92xsrzAeLRHngP2et3j=bmAAw9M257tdzKr1KN9tfpVm=sGw@mail.gmail.com>
	<1336590679429-5698263.post@n5.nabble.com>

On Wed, 9 May 2012 12:11:19 -0700 (PDT), mephysto wrote:
> Hi Kevin,
> I will try to explain my scenario: with my application, many users 
> exchange
> message within them. User1 send message to user2 by a web service. 
> This web
> service send message and wait the response from user 2 before end and 
> send
> notice to user1. I can't know how many time is needed for response, 
> so, I
> would to save te state in a table on database to prevent accidental
> disconnection of client from web service.
>
> But I found that, if transaction are not closed until web service 
> operation
> end, my table are not update, and I can't know the wait state of 
> user1 and I
> can't take back he to his request.
> Moreover, if transaction lock my table, and other user, user3, send a
> message to user4, I can't save his state until user1 operation end.
>
> Is it clear enough?
>
> Is there any wrong in my reasoning? Is there anything I ignore in 
> pool
> functionality?
>
> Thanks in advance.
>
> Mephysto
>
> --
> View this message in context:
> 
> http://postgresql.1045698.n5.nabble.com/Postgres-JDBC-WS-and-commit-tp5697657p5698263.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

Hello,

In Java there are two main ways for Webservices EJB+WS or HTTP+WS 
(JAX-WS, etc). I assume you use EJB+WS, if not give more details. You 
should not manipulate connections pools and transactions manually 
because you will break something.

According to your scenario I guess you use container managed 
transactions in EJB+WS. In this scenario transaction will not be 
committed until method ends, so locks etc, will be preserved, as well 
others will not see Users 1 changes till commit. You should rewrite (a 
little bit) your code, use @TransactionManagement(BEAN), and 
EJBContext.getUserTransactions() or manipulate with 
@TransactionManagement(CONTAINER) (this is default) and 
@TransactionAttribute(REQUIRES_NEW) /your state saving method should be 
in REQUIRES_NEW/ - here I'm not quite sure if in EJB3 to call bean 
method form same bean you need self-inject same bean, or just normal 
Java call is enough.

Please bear in mind, that long running connections (as well JDBC, HTTP, 
IIOP) and transactions may be treated as damaged and closed by server.

Regards,
Radosław Smogura



view thread (17+ messages)  latest in thread

Message-ID: <8f62136f2ac19fb44383745705190955@mail.softperience.eu>
Permalink:  ../8f62136f2ac19fb44383745705190955@mail.softperience.eu/
Also on:    postgresql.org/message-id/8f62136f2ac19fb44383745705190955@mail.softperience.eu

 · 

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: rsmogura@softperience.eu, mephystoonhell@gmail.com
  Subject: Re: Fwd: Postgres JDBC, WS and commit
  In-Reply-To: <8f62136f2ac19fb44383745705190955@mail.softperience.eu>
  References: <1336576000350-5697657.post@n5.nabble.com> <CAC92xsrzAeLRHngP2et3j=bmAAw9M257tdzKr1KN9tfpVm=sGw@mail.gmail.com> <1336590679429-5698263.post@n5.nabble.com> <8f62136f2ac19fb44383745705190955@mail.softperience.eu>

* 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