ejbRemove() can't be rollback?

Discussions

EJB programming & troubleshooting: ejbRemove() can't be rollback?

  1. ejbRemove() can't be rollback? (4 messages)

    String userName,userID,classID;
        try {
          Context ctx = new InitialContext();
          UserHome userHome = (UserHome) ctx.lookup("java:/comp/env/User");
          User user = userHome.findByPrimary(Integer.valueOf(userID);
          userHome.remove(userName);
          ClassanduserHome cauHome = (ClassanduserHome) ctx.lookup(
              "java:/comp/env/Classanduser");
          cauHome.create(Integer.valueOf(userID), Integer.valueOf(classID));
        }
        catch (Exception e) {
          sessionContext.setRollbackOnly();
          System.out.println(e.getMessage());
        }
    when cauHome.create() throw a Exception
    userHome.remove() do not rollback
    but when i replace userHome.remove() with user.setName("dfd")
    when cauHome.create() throw a Exception
    user.setName("dfd") rollback success
    who can tell me why?

    Threaded Messages (4)

  2. If the remove() method doesn't rollback, I'd say its not in the same transaction. One way that could happen is if ejbRemove() and setName() don't have the same transactional attributes declared. If that doesn't do it, I'm out of ideas :-)
  3. re[ Go to top ]

    Mitchell Ratisher :
       can you tell me how to make sure that remove() method and setName() in the
    same transaction?

       thanks
  4. re[ Go to top ]

    Just use the Required transaction attributes for both the EJBs.
  5. re[ Go to top ]

    i try that but it doesn't work yet