Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0 M5
    • Fix Version/s: 1.4 M1 (Codd)
    • Component/s: Mapping
    • Labels:
      None
    • Environment:
      Any

      Description

      DbRef's appear to be loaded eagerly.

      Would be nice if there was support for storing DbRef's on a document but being able to lazy (or manually) load them.

        Issue Links

          Activity

          Show
          Thomas Darimont added a comment - - edited Added Initial POC: https://github.com/spring-projects/spring-data-mongodb/compare/DATAMONGO-348
          Hide
          regis added a comment -

          We should stick by default to eager loading (like you propose), we will still compatible with the old behavior. And not breaking apps when they are going to update the version of spring mongo.

          Show
          regis added a comment - We should stick by default to eager loading (like you propose), we will still compatible with the old behavior. And not breaking apps when they are going to update the version of spring mongo.
          Hide
          Mikkel Dan-Rognlie added a comment - - edited

          I also think eager loading should be the default. Maybe we could have the possibility to change it globally as a property on MappingMongoConverter. Like for instance the disable-validation attribute? Then one could override it with individual @DBRef(lazy = true|false) on entities.

          If it's not too complicated I think it would be nice to support arbitrary types using CGLIB / ASM. But as you said, maybe it is not desirable with the restrictions on field access (could be perceived as 'magical' etc). If it makes the implementation easier it would be ok to require an interface in order to use JDK proxies.

          I don´t think it should be limited to collection types. If you in a query gets a long list of documents, where each doc has deep nested documents, which at arbitrary levels of nesting has one @DBRef, it is still a lot of extra fetches even though the individual @DBRef fields are not collections.

          Show
          Mikkel Dan-Rognlie added a comment - - edited I also think eager loading should be the default. Maybe we could have the possibility to change it globally as a property on MappingMongoConverter. Like for instance the disable-validation attribute? Then one could override it with individual @DBRef(lazy = true|false) on entities. If it's not too complicated I think it would be nice to support arbitrary types using CGLIB / ASM. But as you said, maybe it is not desirable with the restrictions on field access (could be perceived as 'magical' etc). If it makes the implementation easier it would be ok to require an interface in order to use JDK proxies. I don´t think it should be limited to collection types. If you in a query gets a long list of documents, where each doc has deep nested documents, which at arbitrary levels of nesting has one @DBRef, it is still a lot of extra fetches even though the individual @DBRef fields are not collections.
          Hide
          Thomas Darimont added a comment - - edited

          Hi,

          could you please give us some feedback on our current POC for lazy loading of MongoDB associations:
          https://github.com/spring-projects/spring-data-mongodb/compare/DATAMONGO-348

          At the moment we support lazy loading for interface, concrete types, as far as they provide an appropriate parameterless ctor.
          The @PersistenceConstructor annotation is supported as well.
          If there is a need to support arbitrary constructors, we could also try to back-port the Objenesis stuff from
          Spring Framework 4.0 (https://github.com/spring-projects/spring-framework/pull/327)
          The actual loading is performed only once and is triggered when a method on the proxy is called.

          If you want to give it a try, then please do the following:

          • Change the version of your mongodb dependency to: 1.4.0.DATAMONGO-348-SNAPSHOT
          • Add the spring source snapshot-repository
            <repositories>
                <repository>
                    <id>repository.springsource.snapshot</id>
                    <name>SpringSource Snapshot Repository</name>
                    <url>http://repo.springsource.org/snapshot</url>
                </repository>
            </repositories>
            

          Cheers,
          Thomas

          Show
          Thomas Darimont added a comment - - edited Hi, could you please give us some feedback on our current POC for lazy loading of MongoDB associations: https://github.com/spring-projects/spring-data-mongodb/compare/DATAMONGO-348 At the moment we support lazy loading for interface, concrete types, as far as they provide an appropriate parameterless ctor. The @PersistenceConstructor annotation is supported as well. If there is a need to support arbitrary constructors, we could also try to back-port the Objenesis stuff from Spring Framework 4.0 ( https://github.com/spring-projects/spring-framework/pull/327 ) The actual loading is performed only once and is triggered when a method on the proxy is called. If you want to give it a try, then please do the following: Change the version of your mongodb dependency to: 1.4.0. DATAMONGO-348 -SNAPSHOT Add the spring source snapshot-repository <repositories> <repository> <id> repository.springsource.snapshot </id> <name> SpringSource Snapshot Repository </name> <url> http://repo.springsource.org/snapshot </url> </repository> </repositories> Cheers, Thomas
          Hide
          Oliver Gierke added a comment -

          This merged into master. I added an optional dependency to Objenesis to be able to create proxies for classes without a default constructor. Feedback appreciated.

          Show
          Oliver Gierke added a comment - This merged into master. I added an optional dependency to Objenesis to be able to create proxies for classes without a default constructor. Feedback appreciated.

            People

            • Assignee:
              Thomas Darimont
              Reporter:
              Steve Mosley
            • Votes:
              26 Vote for this issue
              Watchers:
              23 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Agile