You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Hassan Abolhassani <Ha...@xist-i.co.jp> on 2004/02/25 08:33:25 UTC

Transaction processing

Hi,

I have a code like below to update several tables in one transaction:

Connection con;
try{
    con = Torque.getConnection();
    Agency agency = new Agency(); 
    ...
    agency.save(con);
    ...

    Product product = new Product(); 
    ...
    product.save(con);


} catch (Exception e) {
   con.rollback();
} 
finally {
    if (null != con) {
        try {
            Torque.closeConnection(con);
        } catch (Exception exp) {}
    }
}


When an exception occures inside the main block, the rollback() is not
working. I mean some save operations updates database anyways.

I am using postgress. Could anybody tell me how it might work?

Regards,
Hassan

___

xist-i Japan, Inc.

アボルハッサニ ハッサン   Dr. Hassan Abolhassani  [Technology network]
株式会社 レーザーフィッシュ・ジャパン
Hassan.Abolhassani@razorfish.co.jp
Tel:03-5436-9980 Fax:03-5436-9126


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


Re: Transaction processing

Posted by Scott Eade <se...@backstagetech.com.au>.
Hassan Abolhassani wrote:

>I have a code like below to update several tables in one transaction:
>
>Connection con;
>try{
>    con = Torque.getConnection();
>    Agency agency = new Agency(); 
>    ...
>    agency.save(con);
>    ...
>
>    Product product = new Product(); 
>    ...
>    product.save(con);
>
>
>} catch (Exception e) {
>   con.rollback();
>} 
>finally {
>    if (null != con) {
>        try {
>            Torque.closeConnection(con);
>        } catch (Exception exp) {}
>    }
>}
>
>
>When an exception occures inside the main block, the rollback() is not
>working. I mean some save operations updates database anyways.
>
>I am using postgress. Could anybody tell me how it might work?
>
You are simply sharing a connection, not using a transaction. You need
to do something like this:

Connection conn = null;
try
{
    conn = Transaction.begin(Torque.getDefaultDB());
    someObject.save(conn);
    someOtherObject.save(conn);
    Transaction.commit(conn);
}
catch (TorqueException ex) 
{
    try
    {
        Transaction.rollback(conn);
    }
    catch (TorqueException ex2)
    { 
        log.error(ex2);
    }
    log.error(ex);
}



BTW: In the future can you please post as plain text rather than html.

Scott
-- 

Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au



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