1 Reply Latest reply on Dec 29, 2006 5:59 PM by Norman Richards

    Transaction rollback doesn't work

    Bram Biesbrouck Newbie

      Hello,

      I've got major problems with my transaction-rollback implementation, and I'm reading manuals for over two days now (I really like
      http://svn.nuxeo.org/nuxeo/ECMPlatform/NXCore/trunk/doc/Transactions.txt ), and I'm getting frustrated.

      The problem is fairly easy; I'm implemention a user-registration action bean, RegisterAction, that implements IRegister, marked @Local. Here it is:

      @Stateful
      @Scope(CONVERSATION)
      @Name("register")
      public class RegisterAction implements IRegister
      {
       @In(create=true) @Out
       private Person currentUser;
       @In(create=true) @Out
       private LoginEntity loginEntity;
      
       @PersistenceContext
       private EntityManager em;
      
       public RegisterAction()
       {
       }
      
       @Rollback(ifOutcome= {"failure"})
       @End
       public String register()
       {
       try {
       this.em.persist(this.currentUser);
       this.em.persist(this.loginEntity); //this one throws an Exception
       }
       catch (Exception e) {
       return "failure";
       }
      
       return "success";
       }
       @Remove @Destroy
       public void destroy()
       {
       }
      }
      


      As you can see, I try to persist two objects, the first one succeeds (and is
      persisted in the DB), the second one doesn't and throws an exception, causing
      the method to return "failure" and should rollback, but it doesn't: the first
      objects gets persisted in the DB, but it should't, because of the rollback.

      Please tell me what I'm doing wrong or what misconfiguration I'm overseeing.

      regards,

      Bram