Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 95D819E8852 for ; Wed, 9 May 2012 17:30:58 -0300 (ADT) Received: from static-ip-217-118-26-141.inaddr.ip-pool.com ([217.118.26.141] helo=mail.softperience.eu) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SSDXE-0002DB-Fi for pgsql-jdbc@postgresql.org; Wed, 09 May 2012 20:30:58 +0000 Received: from mail.softperience.eu (loft2296 [217.118.26.141]) by mail.softperience.eu (Postfix) with ESMTPA id CCE2EC00035; Wed, 9 May 2012 22:30:41 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Date: Wed, 09 May 2012 22:30:41 +0200 From: =?UTF-8?Q?Rados=C5=82aw_Smogura?= To: mephysto Cc: Subject: Re: Fwd: Postgres JDBC, WS and commit In-Reply-To: <1336590679429-5698263.post@n5.nabble.com> References: <1336576000350-5697657.post@n5.nabble.com> <1336590679429-5698263.post@n5.nabble.com> Message-ID: <8f62136f2ac19fb44383745705190955@mail.softperience.eu> X-Sender: rsmogura@softperience.eu User-Agent: Roundcube Webmail/0.5.4 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -0.8 (/) X-Archive-Number: 201205/21 X-Sequence-Number: 22921 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=20 > exchange > message within them. User1 send message to user2 by a web service.=20 > This web > service send message and wait the response from user 2 before end and=20 > send > notice to user1. I can't know how many time is needed for response,=20 > 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=20 > operation > end, my table are not update, and I can't know the wait state of=20 > 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=20 > pool > functionality? > > Thanks in advance. > > Mephysto > > -- > View this message in context: >=20 > http://postgresql.1045698.n5.nabble.com/Postgres-JDBC-WS-and-commit-tp5= 697657p5698263.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=20 (JAX-WS, etc). I assume you use EJB+WS, if not give more details. You=20 should not manipulate connections pools and transactions manually=20 because you will break something. According to your scenario I guess you use container managed=20 transactions in EJB+WS. In this scenario transaction will not be=20 committed until method ends, so locks etc, will be preserved, as well=20 others will not see Users 1 changes till commit. You should rewrite (a=20 little bit) your code, use @TransactionManagement(BEAN), and=20 EJBContext.getUserTransactions() or manipulate with=20 @TransactionManagement(CONTAINER) (this is default) and=20 @TransactionAttribute(REQUIRES_NEW) /your state saving method should be=20 in REQUIRES_NEW/ - here I'm not quite sure if in EJB3 to call bean=20 method form same bean you need self-inject same bean, or just normal=20 Java call is enough. Please bear in mind, that long running connections (as well JDBC, HTTP,=20 IIOP) and transactions may be treated as damaged and closed by server. Regards, Rados=C5=82aw Smogura