0 Replies Latest reply on Jul 3, 2004 6:21 AM by Mark Mescher

    Problems starting transaction from a servlet

    Mark Mescher Newbie

      Hi out there,
      i have a little problem with transactions (its my first try to use them...).
      Following Scenario:
      I want to call 2 methods of a Session Bean from a Servlet. Both methods are creating a new CMP-Object.
      Well...the first Object should be removed from Database if the second fails...So I thought why not using Transactions.
      This looks like the following:

      javax.naming.Context jndiContext = new javax.naming.InitialContext();
      javax.transaction.UserTransaction ut = (javax.transaction.UserTransaction) jndiContext.lookup("UserTransaction");
      ut.begin();
      User user=sessionbean1.createNewUser();
      Adress adress=sessionbean2.createNewAdress();
      ut.commit;


      This code seems to work fine. If sessionbean2 fails, the correct ut.rollback() in the catch-Block (not shown above) is used (thanks to the debugger;)). But if I look in the Database, the entry from sessionbean1 is not removed...
      Where is the problem?
      Session Beans and CMP'S are both set to transaction type "supports" (with xdoclet). I'm using MySQL 4.0.15-nt (perhaps the database is the problem?).
      Cant I start transactions from the servlet???

      Bye

      Mark