4 Replies Latest reply on May 14, 2003 12:39 PM by nicfournier

    no ejb select in home limitation

    nicfournier

      This week is the first time I needed to get only one field from an ejb. So I set up a find that does so but it did not work.

      Digging up a bit I found the existance of ejb Selects which supported what I want. But they can only be defined in the bean. I was really amazed, I would really like to know the valid technical explaination behind this limitation. But that's not the point of my post.

      Currently I have a field in a bean called category, and I want to know which one are used doing only one access to db. The thing is I need to do a find before being able to call the ejbSelect on the bean. I found two possible workarounds but they do not meat my criteria of no db access:

      1- findAll and take first. With small number of beans, could work ok. But will at least result in a select of the primary keys. But that's not my case, there will be several thousands of rows in my case.

      2-findOne using jboss-ql and putting a LIMIT 1. But then it is not portable and each time I need a ejbSelect I also need to add a findOne.

      Does somebody a better solution ??

        • 1. Re: no ejb select in home limitation

          I'm not sure if this solution is portable or not, but if all you need is the ejbSelect method to be accessible from the home interface this can be done in jboss by first declaring the method on the home interface and then implementing it on the bean and call the ejbSelect method from within this implementation.
          Example:

          public homeInterface extends EJB[Local]Home {
          public String findCategory();
          }


          public Bean implements EntityBean {
          // your original ejbSelect method
          public abstract String ejbSelectCategory();

          // implement home finder method in the bean
          public String ejbHomeFindCategory() {
          return ejbSelectCategory();
          }

          .....
          .....
          }

          I hope this helps.
          kv.

          • 2. Re: no ejb select in home limitation
            nicfournier

            I tried what you said unsing jboss 3.2 and I got this error:

            Section: 10.6.2
            Warning: CMP entity beans may not define the implementation of a finder.

            And it does not deploy.

            Do I miss something??

            • 3. Re: no ejb select in home limitation

              No you're not missing anything.
              Forgive me - my mistake.
              It's the word 'find'. Use another word like 'select'.

              Revised example:

              public homeInterface extends EJB[Local]Home {
              public String selectCategory();
              }


              public Bean implements EntityBean {
              // your original ejbSelect method
              public abstract String ejbSelectCategory();

              // implement home finder method in the bean
              public String ejbHomeSelectCategory() {
              return ejbSelectCategory();
              }

              .....
              .....
              }

              kv.

              • 4. Re: no ejb select in home limitation
                nicfournier

                IT WORKED, thanks a lot !!!

                Do you know if this solution is portable (mean j2ee compliant) ?


                Thanks again!