4 Replies Latest reply on Dec 21, 2011 6:54 AM by Aliaksei Lahachou

    EJB method may not be found in base class (EJB 2 Entity Beans)

    Aliaksei Lahachou Newbie

      Hello World!

       

      I'm porting our application to JBoss AS 7 (7.1.0.Beta1b) and and I receive the following error:

       

      JBAS014337: Could not resolve corresponding ejbCreate for home interface method public abstract com.piConsult.piMedia.ejb.entity.util.EJBBaseEntityLocal com.piConsult.piMedia.ejb.entity.util.EJBBaseEntityLocalHome.create(java.util.Map) throws javax.ejb.CreateException on EJB SmartAccessTileParameterEJB

       

      (Full stack is here: http://pastebin.com/raw.php?i=rZ8i4NN5)

       

      SmartAccessTileParameterBean does not contain ejbCreate method, because it is implemented in base class:

       

      public class SmartAccessTileParameterBean extends EJBBaseEntityBean implements SmartAccessTileParameterBeanPersistence

      {

          ...

      }

       

      public abstract class EJBBaseEntityBean extends EJBBase implements IBaseEntityBean

      {

          @Override

          public Object ejbCreate(Map<String, Object> params) throws CreateException

          {

              ...

          }

      }

       

      This code works in AS 4.2.3.GA, and I think it is working in AS 6. Is this a known problem, should I create an issue for this?

       

       

      Regards

        • 1. Re: EJB method may not be found in base class (EJB 2 Entity Beans)
          Carlo de Wolf Master

          While technically such an ejbCreate is viable, it is a violation of the spec:

           

          EJB 3.1 FR 8.6.4 ejbCreate<METHOD> Methods

          The return type must be the entity bean’s primary key type.

           

          The exception says exactly (in too much detail ) which method is missing.

          • 2. Re: EJB method may not be found in base class (EJB 2 Entity Beans)
            Aliaksei Lahachou Newbie

            May be I'm missing something, this is the first time I'm dealing with EJB 2 entity beans, but:

             

            • According to EJB 3.1 FR 8.6.4, ejbCreate<METHOD> Methods:
              • The return type must be the entity bean’s primary key type.
            • According to EJB 3.1 FR 8.6.12, Entity Bean's Local Home Interface:
              • The return type for a create<METHOD> method on the local home interface must be the entity bean’s local interface type.
              • Each create method name must match one of the ejbCreate<METHOD> methods defined in the enterprise bean class. The matching ejbCreate<METHOD> method must have the same number and types of its arguments. (Note that the return type is different.)

             

            So, here's the local home interface:

             

            {code}

            public interface SmartAccessTileParameterHome extends EJBBaseEntityLocalHome

            {

                ...

            }

             

            public interface EJBBaseEntityLocalHome extends EJBLocalHome

            {

                public EJBBaseEntityLocal create(Map<String, Object> params) throws CreateException;

             

                ...

            }

            {code}

             

            Here's the bean class (I changed it to return Integer from ejbCreate):

             

            {code}

            public class SmartAccessTileParameterBean extends EJBBaseEntityBean implements SmartAccessTileParameterBeanPersistence

            {

               ...

            }

             

            public abstract class EJBBaseEntityBean extends EJBBase implements IBaseEntityBean<Integer>

            {

                @Override

                public Integer ejbCreate(Map<String, Object> params) throws CreateException

                {

                    ...

                }

             

                ...

            }

            {code}

             

            And here's the descriptor for complete picture:

             

            {code:xml}

            <entity>

                <ejb-name>SmartAccessTileParameterEJB</ejb-name>

                <local-home>com.piConsult.piMedia.ejb.entity.smartaccess.SmartAccessTileParameterHome</local-home>

                <local>com.piConsult.piMedia.ejb.entity.util.EJBBaseEntityLocal</local>

                <ejb-class>com.piConsult.piMedia.ejb.entity.smartaccess.SmartAccessTileParameterBean</ejb-class>

                <persistence-type>Bean</persistence-type>

                <prim-key-class>java.lang.Integer</prim-key-class>

                <reentrant>True</reentrant>

                <security-identity>

                    <use-caller-identity />

                </security-identity>

            </entity>

            {code}

             

            So, to me everything looks right: bean has ejbCreate which returns Integer, local home interface has create which returns local interface. Still get the same error.

            • 3. Re: EJB method may not be found in base class (EJB 2 Entity Beans)
              Aliaksei Lahachou Newbie

              BTW, I also tried to put ejbCreate directly in bean, and it worked. The following fixes this particular case:

               

              {code}

              public class SmartAccessTileParameterBean extends EJBBaseEntityBean implements SmartAccessTileParameterBeanPersistence

              {

                  @Override

                  public Integer ejbCreate(Map<String, Object> params) throws CreateException

                  {

                      return super.ejbCreate(params);

                  }


                  ...

              }

              {code}

               

              I can't find any statement in spec, which says that ejbCreate may not be defined in base class. Assuming that it worked in past, I believe that it should also work in AS 7.1. Do you know if other containers dis/allow ejbCreate in base classes?

              • 4. Re: EJB method may not be found in base class (EJB 2 Entity Beans)
                Aliaksei Lahachou Newbie

                Hello Carlo,

                 

                your answer was correct, I just got confused by multiple levels of inheritance and interfaces, it's an old application with lots of spaghetti inside (examples above are actually simplified). I managed to find the error only after debugging through AS 7 deployment code >;)