7 Replies Latest reply on Oct 3, 2002 11:35 AM by joeho

    Transaction error handling

    joeho

      Dear all,

      I try to capture error and throw as an application error. But the EJB will not do rollback in this case. I have tried to use setRollBackonly() only to do the rollback but still application error cannot be throw. (I guess setRollback() will throw runtime error also).

      How can I rollback the transaction with throwing application error since I need to throw my own error code?

      Thanks a lot

      Joe

        • 1. Re: Transaction error handling

          The short answer is don't throw Runtime or Remote
          exceptions and use setRollbackOnly.

          Regards,
          Adrian

          • 2. Re: Transaction error handling
            joeho

            But the problem when I use setRollback only, it will throw runtime exception e.g.
            ...
            catch{
            setRollbackonly();
            throw AppException();
            }
            ...

            Runtime exception was thrown automatically and cannot reach "throw AppException()"

            Thanks

            • 3. Re: Transaction error handling

              What runtime exception is it throwing?

              Are you sure AppException isn't a RuntimeException?

              Regards,
              Adrian

              • 4. Re: Transaction error handling
                joeho

                I have tried this in session bean:
                try{
                ...
                //call entity bean here
                ...
                }
                catch
                {
                setRollbackOnly();
                System.out.println("After roll back");
                throw AppException();
                }
                ...

                I cannot get the message in log and nullpointer exception was received in caller session bean.

                Thanks

                • 5. Re: Transaction error handling
                  joeho

                  I have tried this in session bean:
                  try{
                  ...
                  //call entity bean here
                  ...
                  }
                  catch
                  {
                  setRollbackOnly();
                  System.out.println("After roll back");
                  throw AppException();
                  }
                  ...

                  I cannot get the message in log and nullpointer exception was received in caller.

                  Thanks

                  • 6. Re: Transaction error handling

                    That isn't even valid java :-)

                    Which version are you using, I know there
                    was some tidying up of the Exception handling in 3.0.1

                    If you still have a problem, can you post a simple
                    jar (with source) that illustrates it?

                    Regards,
                    Adrian

                    • 7. Re: Transaction error handling
                      joeho

                      I have solved the problem. It is because I cannot get the correct sessioncontext. Then error occurred at 'sessioncontext.setRollbackOnly()' and nullpointerException was thrown.

                      Warjort, thank you for your help!!