3 Replies Latest reply on Mar 4, 2003 1:51 AM by Niklas Uhrberg

    Finder method returning Collection using only a single sql q

    Niklas Uhrberg Newbie

      Hi, I have a simple question:

      How to configure a finder method that returns a Collection that only uses a single sql query to the database to find the entities and load them with data ?

      I use a read-only CMP2.0 entity bean with a compound primary key. I have played around with the read-ahead element and various commit-options but with no success.

      When I look at the debug logging information I can see that JBoss (3.0.4) issues one select operation to obtain the collection matching the search criteria and them one select operation for each entity to fetch data.

      I want one example that works the way I want it to work, not so much as to find out what I'm doing wrong at the moment.

      Thanks !

        • 1. Re: Finder method returning Collection using only a single s
          R.H. Stine, Jr. Newbie

          What you're seeing is a design decision to use "lazy" data retrieval. I don't know whether all EJB containers use this approach, but I wouldn't be surprised, since the implementations for ejbFind methods return primary keys rather than entire beans.

          For what it's worth, this approach can work really well when paging through a large volume of rows.

          I could be wrong, but I don't believe that there is any way for you to change the behavior you describe. If you want to retrieve the data with a single select, you'll probably need to use straight JDBC rather using an entity beans finder method.

          • 2. Re: Finder method returning Collection using only a single s
            Niklas Uhrberg Newbie

            I tried the same kind of scenario on another application and it actually worked perfectly well this time.

            The different read-ahead strategies gave the following results:
            1. none - One select per entity
            2. on-load One select per number of page-size entities. page-size is an element of the read-ahead element (jbosscmp-jdbc.xml) that specifies the number of entities to read in a chunk.
            3. on-find Only one single query for the entire find operation including data loading.

            I do a findByName(String name) and then invoke some getter methods on the local interfaces obtained in the finder method.

            I will now return to the original application and try again.

            BTW: It is true that BMP finder methods return primary keys and it's quite another story in the BMP case.
            However, when doing CMP the container can easily load the entities with data in the same operation that the finder executes.

            Regards ,

            Niklas

            • 3. Re: Finder method returning Collection using only a single s
              Niklas Uhrberg Newbie

              Never mind, everything works just fine. I was a little bit too fast in posting the original message in this thread. Sorry !