Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 76336 invoked from network); 10 Apr 2006 19:06:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Apr 2006 19:06:34 -0000 Received: (qmail 91415 invoked by uid 500); 10 Apr 2006 19:06:33 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 91087 invoked by uid 500); 10 Apr 2006 19:06:32 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 91076 invoked by uid 99); 10 Apr 2006 19:06:32 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Apr 2006 12:06:32 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 10 Apr 2006 12:06:32 -0700 Received: (qmail 76232 invoked by uid 1977); 10 Apr 2006 19:06:11 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 10 Apr 2006 19:06:11 -0000 Date: Mon, 10 Apr 2006 12:06:11 -0700 (PDT) From: Thomas Fischer To: Apache Torque Users List Subject: RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement In-Reply-To: <20060410164844.94287.qmail@web32806.mail.mud.yahoo.com> Message-ID: <20060410120256.O74148@minotaur.apache.org> References: <20060410164844.94287.qmail@web32806.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam-Rating: localhost 1.6.2 0/1000/N X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N The code now looks good. It's fine to rollback after you do the commit. Thomas On Mon, 10 Apr 2006, Jim Caserta wrote: > So if I'm using the following code below, > My question is: > Even if the connection is fine and the database logic > does it's stuff correctly (Do Stuff).. > And the connection is NOT closed. It's ok to do the > "rollback" since the commit worked fine also. correct? > > Connection dbConn = null; > try { > dbConn = > Torque.getConnection("db2.torque.environment"); > ////Do Stuff > dbConn.commit(); > } > finally { > if (dbConn == null) { > //Connection error logic > } > if (!dbConn.isClosed()) { > dbConn.rollback(); > dbConn.close(); > } > } > > --- Thomas Fischer wrote: > >> >> Jim Caserta schrieb am >> 10.04.2006 17:40:05: >> >>> Sorry about the confusion. I meant using >>> Torque.getConnection() and dbConn.close() instead >> of >>> Transaction.begin().. >> >> For any DB which supports transactions: _Make sure_ >> that the connection is >> in autocommit mode or use Transaction.begin and >> Transaction.commit() or do >> both. If you do not commit/rollback and are not in >> autocommit mode you can >> run into ugly trouble (e.g. if the transaction >> serialization is read >> committed, other connections will never see the >> changes to the data in the >> uncommitted transaction and the like). >> >>> And if iI was. the following would work well? >>> >>> >>> Connection dbConn = null; >>> try { >>> // get a connection from the pool >>> dbConn = >>> Torque.getConnection(db2.torque.environment); >>> ////Do Stuff >>> //Commit the transaction >>> dbConn.commit(); >>> } >>> finally { >>> if (!dbConn.isClosed()) { >>> // some error occurred, try to rollback >> and return >>> connection to the pool >>> dbConn.close(); >>> dbConn.rollback(); //Is this needed? >>> } >>> } >> >> This is similar to an earlier version I used some >> time ago. The problem is >> it would throw a NullPointerException in the finally >> block if >> Torque.getConnection() fails. Also, you should >> rollback() before you >> close(). >> >> Whatever code you use in the end, make sure (i.e. >> _test_) that an error in >> retrieving/working with the connection is handled >> correctly. >> >> Thomas >> >> >> > --------------------------------------------------------------------- >> To unsubscribe, e-mail: >> torque-user-unsubscribe@db.apache.org >> For additional commands, e-mail: >> torque-user-help@db.apache.org >> >> > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org > For additional commands, e-mail: torque-user-help@db.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org