10 Replies Latest reply on Oct 29, 2001 9:03 PM by Mack

    How to make findAll() return a sorted collection

    Mack Newbie

      Hi all,

      Need advice on how to make findAll() return a sorted collection. I tried to override findAll in JAWS file, but it won't work (Example is below)


      findAll

      custCode ASC


      Appreciate if anyone can help me,

      Mack

        • 1. Re: How to make findAll() return a sorted collection
          hamish carpenter Newbie

          This seems to work for me. Although I don't know why I need to specify the query line but like you, it doesn't seem to work without it.

          findAll
          id like "%"
          lastName, firstName
          <read-ahead>true</read-ahead>



          • 2. Re: How to make findAll() return a sorted collection
            hamish carpenter Newbie

            > findAll

            If its not just a type then the above line would cause problems. ;)

            • 3. Re: How to make findAll() return a sorted collection
              Mack Newbie

              Hi,

              It doesn't seem to work for my case, but there is a difference in the order (Although not sorted). For example for list of 10 items, sometimes 5 of them are sorted, the rest are not. WEIRD.

              Anyway, thanks for your guides, I really appreciate that.

              Anyone else can help me? Thanks in advance...

              Mack

              • 4. Re: How to make findAll() return a sorted collection
                Franco Apprentice

                Hi,
                change:

                to
                1 = 1

                than it will work.
                Ciao.

                • 5. Re: How to make findAll() return a sorted collection
                  Dan Christopherson Newbie

                  There are some issues with the 2.4.x versions that might make JBoss ignore your sort parameter. The workaround is to use a different name and specify the dummy where clause (1 = 1). I'll get a fix in soon.

                  • 6. Re: How to make findAll() return a sorted collection
                    Mack Newbie

                    Hi all,

                    I have tried to change the query to a dummy one (1 = 1), but the result is still an unsorted list. May I know what you meant by using a different name?

                    I don't know what is wrong with my program and JBoss, anyway, here I include a code snippet which attempts to list the the collection returned by the entity bean:

                    Collection collection = customerHome.findAll();
                    ArrayList arrayList = new ArrayList();
                    Iterator iterator = collection.iterator();
                    while(iterator.hasNext())
                    { Customer customer = (Customer)iterator.next();
                    CustomerData customerData = customer.getCustomer();
                    arrayList.add(customerData);
                    }
                    return arrayList;

                    Where CustomerData is the encapsulating class for all customer fields.

                    And my finder declaration:


                    findAll
                    1 = 1
                    custCode ASC
                    <read-ahead>true</read-ahead>


                    Once again, thanks for everyone's suggestions. I hope that someone will try to see the code above, and if I have done something wrong, I will be grateful if being guided on this issue.

                    Thanks,

                    Mack

                    • 7. Re: How to make findAll() return a sorted collection
                      Franco Apprentice

                      We have a lot of these query's and works fine.
                      Try to remove the ASC to see if something changes.
                      In addition you could install P6Spy (very simple) to look at the generated SQL statements.
                      Ciao.

                      • 8. Re: How to make findAll() return a sorted collection
                        Mack Newbie

                        Hi,

                        Feel a little bit awkward of keeping all of you busy solving my problem. Thanks. However, no matter how I tried in accordance with what you said, my program still doesn't work as I expect.

                        I have installed the P6Spy to trace the SQL call, and I found out that no matter how I changed the finder setting, the SQL Statement is still the simple SELECT statement (Log snippet below)

                        1004344134753|SELECT Salesman.SlsmanCode,Salesman.SlsmanAddr3,Salesman.SlsmanAddr2,Salesman.SlsmanName,Salesman.SlsmanAddr1,Salesman.Version,Salesman.SlsmanContact,Salesman.SlsmanOprType,Salesman.SlsmanVanCode,Salesman.SlsmanAddr4 FROM Salesman |SELECT Salesman.SlsmanCode,Salesman.SlsmanAddr3,Salesman.SlsmanAddr2,Salesman.SlsmanName,Salesman.SlsmanAddr1,Salesman.Version,Salesman.SlsmanContact,Salesman.SlsmanOprType,Salesman.SlsmanVanCode,Salesman.SlsmanAddr4 FROM Salesman

                        It seems that my JBoss won't follow the setting....!!! Any more helps or suggestions...???

                        JBoss Version: 2.4.1
                        Tomcat Version: 3.2.3

                        Thanks,

                        Mack

                        • 9. Re: How to make findAll() return a sorted collection
                          Franco Apprentice

                          My nhe next suggestion mybe to create a new findAll (finAllSorted)and see if it works...

                          Ciao.

                          • 10. Re: How to make findAll() return a sorted collection
                            Mack Newbie

                            Hi,

                            I finally make my program work after following your suggestion by defining a custom findAll (for example, findAllSorted). Anyway, I just feel weird how come some of you have successfully overriden the findAll method and made it work, but mine will never succeed... Anyway, thanks to all of you for your precious comments and suggestions.

                            Mack