Announcement Announcement Module
No announcement yet.
About the number of SQL requests Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • About the number of SQL requests

    Hello all,

    I'm starting to learn Spring and Hibernate and I'm also starting to use SpringRoo.

    I have (for example) a company table CPY that is connected to :
    - several contatcs T_CNT
    - several accounts T_FAC
    - several lines T_LIN
    - several offices T_OFF

    Here is an extract of the TCPY_Roo_DbManaged.aj file :
        @OneToMany(mappedBy = "cpyOid")
        private Set<TCnt> TCpy.tCnts;
        @OneToMany(mappedBy = "cpyOid")
        private Set<TFac> TCpy.tFacs;
        @OneToMany(mappedBy = "cpyOid")
        private Set<TLin> TCpy.tLins;
        @OneToMany(mappedBy = "cpyOid")
        private Set<TOff> TCpy.tOffs;
    What surprizes me is that it generates (at least) 105 requests when I try to show 10 records of the CPY list (with the default generated SpringRoo UI : list.jspx) ...

    One told me that I will face performance troubles when the application will be deployed and when there will be thousands of records and users that will try to use it ...

    So I'd like to understand why there are so much requests, and how I can (if it is possible) reduce the number of requests ?

    I'm not aware of fetch and lazy/eager stuffs ... I tried to apply both values to the oneToMany relations but I didn't manage to enhance things ...

  • #2
    Do you have any method like populateXXXs() (with @ModelAttribute annotation) in your or in Roo_controller.aj files (where XXX is your entity name)?

    If yes, these populate methods try to load all the records from the database tables to be used as drop downs in front end. If you do not need them, modify the code.



    • #3
      Hello pnvsgupta,

      thanks for your clue : it seems that we are on the right way.

      I made a test for one of my classes, replacing the following code :
       @ModelAttribute("tcnts")    public Collection<TCnt> TCpyController.populateTCnts() {
              return TCnt.findAllTCnts();
      by this one :
       @ModelAttribute("tcnts")    public Collection<TCnt> TCpyController.populateTCnts() {
          	return null;
      //        return TCnt.findAllTCnts();
      And it seems that it succeeded, because I don't have this looooong list of requests anymore

      Now I have a question (I'm new in Spring world) : is it possible to remove all those populate method ? for example using an annotation at the right place, or using a particular configuration ?

      I have the possibility to push in all those methods into the corresponding controller, and then change the return value by hand ... but I have a lot of classes and it would represent a huge work ...
      I'd prefer to have an automatic/configuration way to do that.

      Any clue please ?


      • #4
        You might like to vote for ROO-2514 if you think it will help your situation.


        • #5
          Thx Andrew for the link.

          The solution is similar to the one I thought about ... but a bit long to apply, according to the number of methods that I'll have to change by hand

          Maybe I'll do it little by little ...


          • #6
            Hello all,

            you remember the solution proposed by pnvsgupta by the end of June ?

            I just started to implement it but I face a trouble : in some (auto generated) UI pages, I need those drop down lists to create/update records.
            So I started to revert the changes I did, only for the lists I need.

            But, even if all the populate methods are not reverted, I still have a lot of requests (sometime more than 300, just to print one drop list).

            Those populate method are calling some findAllXXX() methods ... and those methods are the origin of all those requests on the server.

            Do you have any idea to prevent for all thoses requests ?