4 Replies Latest reply on Mar 10, 2005 1:10 PM by darranl

    ejbCreate with parameters for Stateless Session Bean

    enterprisejavabones

      Hi,

      I've been trying to create a Stateless Session Bean that has an ejbCreate method that takes some parameters. I'm using JBoss 3.0.8 and was wondering if this is just a version limitation or am i doing something wrong.

      my code looks something like

       public void ejbCreate(String param1, String param2 ) {
       this.param1 = param1;
       this.param2 = param2;
      
       }
      


      When i try to deploy, i get the following

      java.lang.NoSuchMethodException: org.jboss.ejb.StatelessSessionContainer.createHome(java.lang.String, java.lang.String)

      According to the EJB 2.1 Spec (Sec 7.11.3, p110), we should be able to define ejbCreate methods in Session Beans that take parameters. Is it just that 3.0.8 is based on an older version of the EJB spec that didn't allow ejbCreate methods to take arguments?

      btw, i have also provided a default ejbCreate method that takes no parameters.

      Thanks in advance

      Cheers
      Prem

        • 1. Re: ejbCreate with parameters for Stateless Session Bean
          darranl

           

          am i doing something wrong.


          Yes - Stateless session beans are not allowed to take parameters for ejbCreate - the bean instance created is NOT associated with a specific client.

          According to the EJB 2.1 Spec (Sec 7.11.3, p110), we should be able to define ejbCreate methods in Session Beans that take parameters. Is it just that 3.0.8 is based on an older version of the EJB spec that didn't allow ejbCreate methods to take arguments?


          Yes STATEFUL session beans can take parameters. The spec will tell you that stateless beans can not take parameters.

          • 2. Re: ejbCreate with parameters for Stateless Session Bean
            djeang

            Where ?
            I have read the whole spec and I found nowhere that stateless cannot support ejbCreate with parameter ?
            Perhaps i've missed something. Can somebody tell me where exactly on the specs it is specified ?

            Thanks you.

            • 3. Re: ejbCreate with parameters for Stateless Session Bean
              starksm64

              Its rather hard to miss:


              ejb 2.1 spec, 7.11.3 ejbCreate<METHOD> Methods

              The session bean class must define one or more ejbCreate<METHOD> methods whose signatures must follow these rules:
              + The method name must have ejbCreate as its prefix.
              + 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 arguments must be legal types for RMI/IIOP if there is a create<METHOD> corresponding to the ejbCreate<METHOD> method on the session bean?s remote home interface.

              + A stateless session bean must define a single ejbCreate method, with no arguments.

              + The throws clause may define arbitrary application exceptions, possibly including the javax.ejb.CreateException.



              • 4. Re: ejbCreate with parameters for Stateless Session Bean
                darranl

                In the EJB 2.1 specification see section 7.8 'Stateless Session Bean' paragraph 4.