1 Reply Latest reply on Jun 9, 2003 11:24 AM by drcharris

    EJBExceptions in business methods

    mutilin

      My component has a business method that throws EJBException in some cases.

      At first, I invoke this method and it throws ServerException and it should throw it.
      Then, I invoke this method when it shouldn't throw exception, but it throws ServerException again (it says: "could not activate instance, error reading xxx.ser", or something of that kind).

      I think that JBoss removes instance of the component that throws EJBException, but why? Is it J2EE compiliant?


      (I use "Titan" example from O'Really workbook on JBoss
      and I invoke bookPassage() method of TravelAgent component when expiration date of the credit card has been passed.
      Then I invoke bookPassage with a valid credit card, but it throws an exception again)

        • 1. Re: EJBExceptions in business methods
          drcharris

          Yes, it is spec-compliant.

          In a J2EE server there are two kinds of exceptions

          1. System Exceptions
          2. Application Exceptions

          System exceptions are all RuntimeExceptions (and subclasses, this includes EJBException), and RemoteException. If a method throws one of these then the container is obliged to remove the bean instance in which the exception was thrown. The logic here is that, since the exception is unchecked, youve got no real way of recovering from it and therefore the state of your bean instance could be corrupted.

          Application exceptions are propagated just like any other, and don't destroy the bean instance.

          If there's a chance of you recovering from the exception your method is throwing, then you should make it a checked exception and not EJBException.

          The error message you're getting is JBoss trying to activate the bean instance (probably a stateful session bean) in a subsequent call and failing because the bean instance no longer exists.