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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to