5 Replies Latest reply on Feb 4, 2002 5:58 AM by Martin Stepanek

    Calling finder methods from ejbHome<foo> methods with CMP en

    Martin Stepanek Newbie

      Hi all,

      can someone advise, how to call finder methods from a home method? I use JBoss 3.0.0alpha with CMP 2.0 entities. I need a home method, which will take some data, prepare parameters for the finder, call the finder and then return results. I've defined the finder method in the home interface and have the EJB QL for it (it works fine, when I call it from the client). In the bean implementation I have the following code:

      public abstract Collection ejbFindByFoo(Integer foo);

      public Collection ejbHomeFindByData(TreeOM data) {
      <here preparing the data, ie. filling the foo variable>
      Collection res = ejbFindByFoo(foo);
      return res;

      I can see no bug in it, but JBoss always throws this exception:
      javax.ejb.EJBException: Unknown method type: ejbFindByFoo

      Can anyone tell me, what is (or could be) wrong? Please!!!


        • 1. Re: Calling finder methods from ejbHome<foo> methods with CM
          Jason Carroll Newbie

          I could be completely wrong about this, so someone please correct me if I am:

          I don't think you can do this. In CMP 2.0, finder methods are not declared in the bean implementation class, but only in the home interface. I think you have a couple choices, the first is you can get a reference to the Home interface in the home method and then call the finder just like your client does. I tested this and it works fine, but of course now you have a lookup and a couple more objects created.

          The other option is to change your finder method to an ejbSelect method, which is defined in the bean class, and use that in the home method. The downsides of this approach is now you can't make the ejbSelect method available to your remote (or local) client. This might not be an issue for you if you have the home method returning the results. Of course you could have both a finder and select method you just have to maintain both entries in the ejb-jar.xml file. The other downside is that in JBoss there was a bug until yesterday that prevented you from calling ejbSelect methods from Home methods. This should have been fixed though in the current CVS tree so you could always pull that and build it.

          • 2. Re: Calling finder methods from ejbHome<foo> methods with CM
            Dain Sundstrom Master

            EJB home methods are not allowed to start with the words find or create, as these are reserved for find and create methods respecively. JBoss has long supported BMP style customer finders in CMP. Just change the name of your method from ejbHomeFindByData to ejbFindByData, and it should work.

            • 3. Re: Calling finder methods from ejbHome<foo> methods with CM
              Martin Stepanek Newbie

              Thank you very much for your answers, but I still have a question.

              As for the "finder solution": I know the ejbFind<> method implementation is not part of the bean implementation, but I've expected it'll be implemented in the containers bean$proxy. It's not the case, my fault :o) Now, it seems to me little bit circuitous to get the reference to the beans home by lookup only to call its own finder...

              The ejbSelect solution is probably more proper. So I wanted to download the last nightly build of JBoss, but I found out the references are broken. I downloaded CVS client, downloaded the jboss-all module (it took some hours), successfully builded JBoss and deployed my beans... and it doesn't work suddenly:

              I have a session bean with the following method:

              public TreeOM dispose(TreeOM x) {

              where the TreeOM is my class extending Hashtable with some utility methods.
              Jboss suddenly started to throw some strange exceptions about parameter type mismatch and after doing some tests the error changed to:

              16:38:13,861 ERROR [StatefulSessionContainer] invoke returned an exception
              java.lang.NullPointerException: METHOD IS NOT FOUND: -603565233024741760
              at org.jboss.invocation.MarshalledInvocation.getMethod(MarshalledInvocat
              at org.jboss.ejb.Container.invoke(Container.java:573)
              <snipped for brevity>

              I think it's some bug in this CVS version of JBoss, isn't it? But can you please tell, WHERE TO GET THE LAST RELATIVELLY STABLE NIGHTLY BUILD OF JBOSS?

              Sorry, I'm new to CVS. Maybe I've done something wrong...


              • 4. Re: Calling finder methods from ejbHome<foo> methods with CM
                Jason Carroll Newbie

                I'm using a version from CVS from Jan 9 2002. You could checkout the files for that date but the ejbSelect methods won't work from home methods. I haven't tried any newer versions from CVS since they were broken for about a week. Supposedly things are better now so you might want to try again in a day or two. I just got a reference to the home interface and used the finder methods for now until I get a newer copy of JBoss. It is easy to change a finder to a select later when I can.

                I agree that the method should be in the proxy but I couldn't figure out how to compile the bean class without declaring the finder as abstract in the bean class which of course shouldn't be done in CMP. Seems to be a whole chicken and the egg thing. I tried duplicating your code and got the same error you did about the invalid type no matter what I named my findBy and home methods.

                Of course your other option is to follow Dain's suggestion above which sounds like you would replace the home method with a custom finder. I'm no expert but the only way I could get this working, without using one of my suggestions, was to code the SQL directly into the bean class which means you can't define the query in the ejb-jar.xml. Maybe I misunderstood what Dain was saying though.


                • 5. Re: Calling finder methods from ejbHome<foo> methods with CM
                  Martin Stepanek Newbie

                  Thank you for your replies. Finally (because I can't use the ejbSelect), I used the following solution:
                  I send the reference to the EJBs home as a additional parameter of my custom home method and then call the finder on it... It works fine, although it's a little bit ugly solution...