db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Eade <se...@backstagetech.com.au>
Subject Re: Transaction processing
Date Wed, 25 Feb 2004 12:46:23 GMT
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


Mime
View raw message