Spring Roo
  1. Spring Roo
  2. ROO-1636

@Configurable might have impacts on performance. Provide means for alterantive style for injecting EntityManager into domain objects

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 1.1.0.RELEASE
    • Fix Version/s: None
    • Component/s: PERSISTENCE
    • Labels:
      None

      Description

      When having queries with big result sets, @Configurable might have serious impact on performance.

      For example, let's say we have an Entity FooBar, of which we retrieve 80000 instances from DB.

      On my machine the creation of those 80000 instances takes about 7 seconds. Without @Configurable, it takes only some milliseconds. Pefromance monitoring shows, that most time is spent in BreanConfigurerSupport in first case.

      Thus, Roo should allow for some (optional) alternative approach to @Configurable.

      There have been other issues with proposals around here. For instance, there might be a singleton object, where EntityManager is injected and that provides it by some static method to the domain objects.

      Something like this:

      @Configurable
      class DomainObjectConfig{
        @PersistenceContext EntityManager em;
      
        
        public static DomainObjectConfig getSingletonInstance(){ ... }
        public EntityManager getEntityManager(){ return em;}
      }
      

        Activity

        Hide
        Brad Murray added a comment -

        Can I ask why no-one appears to have looked at this? I realize the original reporter left it as a minor improvement, but to be honest its a pretty big issue. We recently had to refactor Roo entirely out of our domain layer in order to permanently remove @Configurable. In its current state, I don't see how you can build a medium/large Roo application without running into massive performance problems in the domain layer. In small applications you just don't realize how much its costing you.

        Its not a problem caused by Roo as such, but the current Spring beans implementation with @Configurable means you can't use it in a domain layer for anything other than a trivial app where the cost isn't important.

        Show
        Brad Murray added a comment - Can I ask why no-one appears to have looked at this? I realize the original reporter left it as a minor improvement, but to be honest its a pretty big issue. We recently had to refactor Roo entirely out of our domain layer in order to permanently remove @Configurable. In its current state, I don't see how you can build a medium/large Roo application without running into massive performance problems in the domain layer. In small applications you just don't realize how much its costing you. Its not a problem caused by Roo as such, but the current Spring beans implementation with @Configurable means you can't use it in a domain layer for anything other than a trivial app where the cost isn't important.
        Hide
        Alan Stewart added a comment -

        Can you please provide a working project with your alternative? I can then look at code-generating it. I'm really time poor at the moment and any help would be appreciated. Perhaps knock up a project with Roo, push-in what you need to modify and use the Roo 'backup' command and attach here.
        Thanks

        Show
        Alan Stewart added a comment - Can you please provide a working project with your alternative? I can then look at code-generating it. I'm really time poor at the moment and any help would be appreciated. Perhaps knock up a project with Roo, push-in what you need to modify and use the Roo 'backup' command and attach here. Thanks
        Hide
        Stefan Ocke added a comment -

        IMHO, the new support for DAOs provides an alternative to @Configurable, since it is not necessary anymore to inject EntityManager into the entities.
        So, as long as the new @RooJpaEntity annotation does not trigger the introduction of @Configurable anymore, I would consider this issues as resolved and I see no strong need for another alternative approach.

        Show
        Stefan Ocke added a comment - IMHO, the new support for DAOs provides an alternative to @Configurable, since it is not necessary anymore to inject EntityManager into the entities. So, as long as the new @RooJpaEntity annotation does not trigger the introduction of @Configurable anymore, I would consider this issues as resolved and I see no strong need for another alternative approach.
        Hide
        Andrew Swan added a comment -

        So, as long as the new @RooJpaEntity annotation does not trigger the introduction of @Configurable anymore, I would consider this issues as resolved and I see no strong need for another alternative approach.

        That is indeed how it works. As a demo, we create an entity called Bar, with active record turned off:

        roo> entity jpa --class ~.Bar --activeRecord no
        Created SRC_MAIN_JAVA/com/bar/Bar.java
        Created SRC_MAIN_JAVA/com/bar/Bar_Roo_ToString.aj
        Created SRC_MAIN_JAVA/com/bar/Bar_Roo_DisplayString.aj
        Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Jpa_Entity.aj

        Only once active record is enabled is the "Configurable" annotation introduced (via the "Bar_Roo_Configurable" ITD):

        ~.Bar roo> entity jpa --class ~.Bar --activeRecord yes
        Updated SRC_MAIN_JAVA/com/bar/Bar.java
        Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Configurable.aj
        Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Jpa_ActiveRecord.aj

        On that basis, I'm marking this ticket as invalid.

        Show
        Andrew Swan added a comment - So, as long as the new @RooJpaEntity annotation does not trigger the introduction of @Configurable anymore, I would consider this issues as resolved and I see no strong need for another alternative approach. That is indeed how it works. As a demo, we create an entity called Bar , with active record turned off: roo> entity jpa --class ~.Bar --activeRecord no Created SRC_MAIN_JAVA/com/bar/Bar.java Created SRC_MAIN_JAVA/com/bar/Bar_Roo_ToString.aj Created SRC_MAIN_JAVA/com/bar/Bar_Roo_DisplayString.aj Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Jpa_Entity.aj Only once active record is enabled is the "Configurable" annotation introduced (via the " Bar_Roo_Configurable " ITD): ~.Bar roo> entity jpa --class ~.Bar --activeRecord yes Updated SRC_MAIN_JAVA/com/bar/Bar.java Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Configurable.aj Created SRC_MAIN_JAVA/com/bar/Bar_Roo_Jpa_ActiveRecord.aj On that basis, I'm marking this ticket as invalid.

          People

          • Assignee:
            Alan Stewart
            Reporter:
            Stefan Ocke
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: