5 Replies Latest reply on Jan 30, 2006 6:28 PM by david diaz

    Throwing javax.ejb.CreateException from ejbCreate() of a MDB

    bcalmac Newbie

      In the ejbCreate() method of my MDB I have some initialization code that can throw exceptions. I'm catching the exceptions and wrap them in an javax.ejb.CreateException. When I deploy the bean, I get:

      17:32:58,416 WARN [org.jboss.ejb.EJBDeployer.verifier] EJB spec violation:
      Bean : StateEngineBean
      Method : public void ejbCreate() throws CreateException
      Section: 15.7.3
      Warning: The ejbCreate() method must define no application exceptions.

      As a result, the bean does not get deployed (I am using jboss 3.2.3).

      Now, does this really violate the EJB spec? The spec says you can't throw application exceptions. javax.ejb.CreateException should be OK.

      I would like to mention that the my MDB simply can't function if the initialization fails and I can't ignore the exception. Ignoring it would mean that I would be consuming events later without being able to process them.

      Is this behaviour by design or is it bug?

      thanks a lot.

        • 1. Re: Throwing javax.ejb.CreateException from ejbCreate() of a
          Elias Ross Master

          You can throw EJBException, which is unchecked. CreateException is checked, which is not allowed. It's also for home interfaces, not JMS.

          • 2. Re: Throwing javax.ejb.CreateException from ejbCreate() of a
            bcalmac Newbie

            Well, I know that I can throw unchecked exceptions but this is a workaround.

            The thing here is that the specification is vague by saying you can't throw application exceptions. The term "application exception" is left up to the interpretation of the implementation.

            I would infer that you should be able to throw "non-application exceptions" which is not the same as unchecked exceptions, because they would have used this more precise term in the first place.

            If you google for "message driven bean ejbcreate createexception" you would find some sample code from other appservers which shows that they allow CreateException.

            • 3. Re: Throwing javax.ejb.CreateException from ejbCreate() of a
              dannyyates Newbie

              Just because other app servers allow something doesn't make it right!

              When you say "left up to the interpretation of the implementation", I assume you haven't read section 18.1.1 of the EJB (2.0) spec?

              • 4. Re: Throwing javax.ejb.CreateException from ejbCreate() of a
                Scott Stark Master

                This case is clearly defined by the ejb 2.1 spec:

                15.7.3 ejbCreate Method
                The message-driven bean class must define one ejbCreate method whose signature must follow these rules:
                The method name must be ejbCreate.
                The method must be declared as public.
                The method must not be declared as final or static.
                The return type must be void.
                The method must have no arguments.
                The throws clause must not define any application exceptions.

                18.1.1 Application Exceptions
                An application exception is an exception defined in the throws clause of a method of an enterprise bean’s home, component, message listener, or web service endpoint interface, other than the java.rmi.RemoteException.


                The javax.ejb.CreateException, javax.ejb.RemoveException, javax.ejb.FinderException, and subclasses thereof are considered to be application exceptions. These exceptions are used as standard application exceptions to report errors to the client from the create, remove,
                and finder methods (see Subsections 10.5.9 and 12.1.10). These exceptions are covered by the rules on application exceptions that are defined in this chapter.

                • 5. Re: Throwing javax.ejb.CreateException from ejbCreate() of a
                  david diaz Newbie

                  I had the same problem, the error was displayed even without the trows clause in the create method. I erased the throws clause from the ejbRemove method and everything worked just fine.

                  I don't understand this error, correct me if Ii'm wrong but the specification doesn't forbid to declare the ejbCreate method with the throws CreateException clause it forbids to actually throw the exception.