7 Replies Latest reply on Feb 27, 2002 10:22 PM by pazu

    dynamic finder method

    smirakr

      Hi,

      I'm working with CMP2.0 EntityBean with JBoss3.0 alpha. I have following problem:

      I want to specify an user filter (eg. using EJBQL or SQL) on client side, call find method on home interface with this filter and obtain collection of beans.

      My question: can I specify dynamic filter on client side? (found nothing in ejb specification 1.1 or 2.0) - If I can not then why? Is any other way how to do that?


      Thanks.

        • 1. Re: dynamic finder method

          Not sure what you mean by user filter. Do you mean you want your finder to return limited results based on user input? Or based on the user identity?

          • 2. Re: dynamic finder method
            smirakr

            I mean limited results based on user input,

            eg. on client side:

            String query = "age > 15"; // client generates query dynamicaly

            PeopleHome h = ... // obtain home of PeopleEntityBean which has a persistent attribute "age"

            Collection beans = h.findByQuery(query);

            • 3. Re: dynamic finder method

              I do something similar to this, but I have developed a reflection framework and utilize a HashMap value object that allows my client side to know what properties are available from a given bean. I couldn't find anything for free in the EJB spec to satisfy this need.

              • 4. Re: dynamic finder method
                dsundstrom

                This is on the features list, but is a very low priority. In the mean time, I suggest that you write a BMP style cutom finder. Just declare your finder in the home and then provide an implementation in you bean implementation class. The method is named ejbFind(your args). This is a pain because you have to write some JDBC code, but usually an application only needs a couple of dynamic finders.

                • 5. Re: dynamic finder method
                  abrasax

                  Hi,

                  I have a similar problem. I also use Hashtable structure for passing flexible parameters to my finder... I've written this finder using JDBC. I create the statement, get some ResultSet and return a collection of primary keys... This works for my BMP beans, but not for CMP2.0 beans. What kind of data is the BMP style finder in a CMP bean expected to return and how can I transform the primary keys into that? Can someone help me?

                  Best regards and thanks
                  Martin Stepanek

                  • 6. Re: dynamic finder method
                    abrasax

                    Sorry, I found, what was wrong, just a few minutes after posting the yester post. I implemented the custom finder as a home method, ie. ejbHomeFindByAnything, instead of ejbFindByAnything, and so the container didn't transform the returned primary keys into proxies... Now it works fine :o) Mea culpa :o)
                    Martin

                    • 7. Re: dynamic finder method
                      pazu

                      You may also want to look at the new EJB-QL query compiler and the Dynamic-QL feature. Take a look at this thread:

                      http://main.jboss.org/thread.jsp?forum=46&thread=9743