Spring Roo
  1. Spring Roo
  2. ROO-2943

All entities being loaded when only one requested

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.5.RELEASE
    • Fix Version/s: None
    • Component/s: PERSISTENCE
    • Labels:
      None

      Description

      Steps to reproduce:

      1. Create a new project using the pet clinic script
      2. Set logging to debug
      3. Run the application and enter on owner and a multiple number of associated pets
      4. call /pets/1
      5. The logs will show that all instances of Pet are queried

      e.g.

      DEBUG org.hibernate.SQL - select pet0_.id as id2_, pet0_.name as name2_, pet0_.owner as owner2_, pet0_.send_reminders as send3_2_, pet0_.type as type2_, pet0_.version as version2_, pet0_.weight as weight2_ from pet pet0_
      DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
      DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.springsource.petclinic.domain.Pet#1]
      DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'com.springsource.petclinic.domain.Pet': PersistenceElement for transient javax.persistence.EntityManager com.springsource.petclinic.domain.Pet.entityManager
      DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
      DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.springsource.petclinic.domain.Pet#2]
      DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'com.springsource.petclinic.domain.Pet': PersistenceElement for transient javax.persistence.EntityManager com.springsource.petclinic.domain.Pet.entityManager
      DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'
      DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.springsource.petclinic.domain.Pet#3]
      DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'com.springsource.petclinic.domain.Pet': PersistenceElement for transient javax.persistence.EntityManager com.springsource.petclinic.domain.Pet.entityManager
      DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'entityManagerFactory'

        Activity

        Hide
        Nick Shaw added a comment - - edited

        This is not an issue if you only have 3 Pets, but say you have thousands? Not only do queries for single Pets take an age to load, but your house smells funny.

        Show
        Nick Shaw added a comment - - edited This is not an issue if you only have 3 Pets, but say you have thousands? Not only do queries for single Pets take an age to load, but your house smells funny.
        Hide
        Daniel Dostal added a comment -

        This is also a problem in 1.2.0.RC1

        Show
        Daniel Dostal added a comment - This is also a problem in 1.2.0.RC1
        Hide
        Daniel Dostal added a comment -

        Oddly enough, a simple fix should be to move those methods into the controller's .java file without the @ModelAttribute annotation, but this causes a NullPointerException:
        NullPointerException at org.springframework.roo.addon.web.mvc.controller.scaffold.WebScaffoldMetadata.<init>(WebScaffoldMetadata.java:170)

        This exception prevents Roo from managing the project properly. Removing the methods allows Roo to control it once again.

        As a note, once the Collections are not part of the uiModel, even the list all command works quickly as it only shows a limited number of entities.

        Show
        Daniel Dostal added a comment - Oddly enough, a simple fix should be to move those methods into the controller's .java file without the @ModelAttribute annotation, but this causes a NullPointerException: NullPointerException at org.springframework.roo.addon.web.mvc.controller.scaffold.WebScaffoldMetadata.<init>(WebScaffoldMetadata.java:170) This exception prevents Roo from managing the project properly. Removing the methods allows Roo to control it once again. As a note, once the Collections are not part of the uiModel, even the list all command works quickly as it only shows a limited number of entities.
        Hide
        Alan Stewart added a comment -

        Can you please attach a modified project that resolves this issue? I can then see about changing the ITD generation. Alternatively, a patch with the changes.

        Show
        Alan Stewart added a comment - Can you please attach a modified project that resolves this issue? I can then see about changing the ITD generation. Alternatively, a patch with the changes.
        Hide
        Nick Shaw added a comment -

        So I had a good look at this over the weekend. I'm convinced that the populate methods don't belong in the ITD. The use cases vary so much that they have to be dealt with case by case. With this in mind I'd expect ROO to deliver something like the attached with a warning to modify the source on Controller creation.

        Adding a ModelAttribute like this is a bit of a brute force approach to getting the requisite data on the forms, create doesn't use it at all for example (unless an entity is self referential). What would be a good fix is a field that can make a paginated or filtered request.

        Thoughts?

        Show
        Nick Shaw added a comment - So I had a good look at this over the weekend. I'm convinced that the populate methods don't belong in the ITD. The use cases vary so much that they have to be dealt with case by case. With this in mind I'd expect ROO to deliver something like the attached with a warning to modify the source on Controller creation. Adding a ModelAttribute like this is a bit of a brute force approach to getting the requisite data on the forms, create doesn't use it at all for example (unless an entity is self referential). What would be a good fix is a field that can make a paginated or filtered request. Thoughts?

          People

          • Assignee:
            Unassigned
            Reporter:
            Nick Shaw
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: