1 Reply Latest reply on Jun 25, 2003 1:41 PM by Adrian Brock

    a problem about Transaction

    cocobase Newbie

      UserTranaction utx = null;
      try {
      Context ctx = new InitialContext();
      utx = (UserTransaction) ctx.lookup("java:/comp/UserTransaction");
      utx.begin();
      UserHome userHome = (UserHome) ctx.lookup("User");
      User user = userHome.findByPrimaryKey(Integer.valueOf("9"));
      user.setName("user1");
      ClassanduserHome home = (ClassanduserHome) ctx.lookup("Classanduser");
      Classanduser classanduser = home.create(Integer.valueOf("2"), Integer.valueOf("2"));
      utx.commit();
      System.out.println(classanduser.getClassID());
      }
      catch (Exception e) {
      System.out.println(e.getMessage());
      }

      Classanduser classanduser = home.create(Integer.valueOf("2"), Integer.valueOf("2")); throw Exception
      user.setName("user1") can rollback

      but when replace user.setName("user1") with
      user.remove() or userHome.create("user2")
      it can't rollback

      who can help me please!