Discussions

EJB design: JTA and rollback problems

  1. JTA and rollback problems (3 messages)

    I have a strange problem. In a servlet, I am starting a Transaction

    UserTransaction ut = mySessionCtx.getUserTransaction();

    and trying to update two tables thru two Entity Beans .

    If both go through successfully i am committing the changes
    using

    ut.commit();

    else I want to roll back. My problem is the first update changes are getting commitied even if the second update is failing . When the second update fails it is giving me a message saying Tansaction Rolled Back but still the first update changes are not being rolled back. The transaction attributes of the session bean are TX_BeanManaged and for Entity beans TX_Supports Any Help please !!!

    Akmal.

    Threaded Messages (3)

  2. JTA and rollback problems[ Go to top ]

    Hi Akmal,

    Can you try the following steps to troubleshoot your problem ?

    1. Obtain a connection from the dataSource (data source to which entity beans are mapped.)
    2. On the connection object call getAutoCommit() and check its value. The value, IMO, shouldnt be true.

    Regards,
    Hemant
    Pramati Technologies
    www.pramati.com
  3. JTA and rollback problems[ Go to top ]

    Thanks Hemant,

    I was slightly wrong in the way I phrased the problem. I am dealing with Enterprise Session (Stateless) Beans not Entity beans (my fault sorry!). The Stateless Session beans use db helper classes instead of Entity beans to do inserts. So I am not sure if you suggestion will work. Any other ideas.

    Thanks Again,

    Akmal.
  4. JTA and rollback problems[ Go to top ]

    Hi Akmal,
    I am also facing the same problem. I am using Weblogic5.1 .My code looks like the following.
    try{
    ut = (javax.transaction.UserTransaction)initial.lookup("javax.transaction.UserTransaction");

    ut.begin();
    calling db method 1 on another bean
    calling db method 2 on another bean
    ut.commit()
    }
    catch(Exception e){
    .....
    ut.rollback();
    ...
    }
    When autocommit is true:
    When the method 2 fails method 1 still commits the changes in the database.

    When autocommit is false:
    When both the method passes still none of them commits the changes in the database.

    If you got any solution to your problem please respond me.