db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement
Date Mon, 10 Apr 2006 16:02:43 GMT

Jim Caserta <smoothie_jc@yahoo.com> 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

Whatever code you use in the end, make sure (i.e. _test_) that an error in
retrieving/working with the connection is handled correctly.


To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message