New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy Load for DbRef [DATAMONGO-348] #1281
Comments
Steven Sheehy commented In addition to lazy loading, I would like to add my support for the manually loading of DBRefs. We are using DBRefs to point to multiple collections and using ObjectIds when the collection name cannot vary as recommended by Mongo (http://www.mongodb.org/display/DOCS/Database+References). As a result, we had to write a custom converter to bypass the automatic fetching of DBRefs that Spring Data defaults to. It would be nice if we didn't have to use a converter and could specify this behavior via the |
Andrew Bethell commented Is another way around this just to not have spring-data map certain fields? If using the MongoRepository - you could do this with the |
Oliver Drotbohm commented Until we eventually get to solve this issue in a nicer way, you can simply have class Account {
@DBRef
DBRef owner;
}
Account account = …;
MongoConverter converter = …;
User user = converter.read(User.class, account.owner.fetch()); |
Tito George commented Work around with DBRef did not work. It failed while saving.
Failed with below ST
From Eclipse when StackOverflowError is caught.
|
David Anderson commented Tito, Oliver's Account class had an error in it, it should have been:
|
Tito George commented David,
Say an instance of User1 can contain list requests and request object can contain User1 (in its fields who or whom). I am able to save User as well as Request. But while querying i am getting https://jira.springsource.org/browse/DATAMONGO-488. So I was hoping Oliver's workaround would solve this. But its failing wile saving. |
Sebastian Julius commented Are there any plans when this feature will be integrated? We're currently creating 4-times more requests to the DB then required. Therefore it'd be brilliant to have lazy loading. Thanks in advance |
regis commented The morphia project also provided this feature.
@Entity("employees")
class Employee {
// auto-generated, if not set (see ObjectId)
@Id ObjectId id;
//refs are stored**, and loaded automatically
@Reference(lazy = true)
List<Employee> underlings = new ArrayList<Employee>();
} Why the spring data team doesnt reply ? Hey guys the ticket is 3 years OLD.... |
Mikkel Dan-Rognlie commented I see that |
Oliver Drotbohm commented Yes |
Thomas Darimont commented How should the lazy loading behaviour be enabled and what should be the default? I would propose something like this, with lazy=false as the default: @DBRef(lazy = true) List<User> fans; Should we support lazy loading for all possible concrete types or just interfaces types or even just for collection types? If we have to support arbitrary types, then we have to enforce some restrictions, e.g. like the fields of the type needn't be accessed directly - just via accessor methods. We could then generate a custom subclass of the given type (via CGLIB / ASM + (maybe) Objenesis for object construction) where we inject a proper initialisation check into the relevant method bodies and perform the required lazy loading logic if necessary and then delegate to the base class implementation |
Thomas Darimont commented Added Initial POC: https://github.com/spring-projects/spring-data-mongodb/compare/DATAMONGO-348 |
regis commented 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. |
Mikkel Dan-Rognlie commented 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 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 |
Thomas Darimont commented Hi, could you please give us some feedback on our current POC for lazy loading of MongoDB associations: At the moment we support lazy loading for interface, concrete types, as far as they provide an appropriate parameterless ctor. If you want to give it a try, then please do the following:
<repositories>
<repository>
<id>repository.springsource.snapshot</id>
<name>SpringSource Snapshot Repository</name>
<url>http://repo.springsource.org/snapshot</url>
</repository>
</repositories> Cheers, |
Oliver Drotbohm commented 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 |
Steve Mosley opened DATAMONGO-348 and commented
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
Affects: 1.0 M5
Reference URL: http://forum.springsource.org/showthread.php?113321-Support-for-lazy-loading-in-Spring-Data-Document
Issue Links:
DATAMONGO-488 Stackoverflow when querying document with cycle reference using
@DBRef
DATAREDIS-470 Lazy Load for
@Reference
Referenced from: commits ea33e8b, 8fb390e, c3f8f1e, df1c449, 785a7ef, fd60d32, c63994e, 1bb29f3, 5e47df1, f33b4ec, 1b2f6a1, a66e762, 1055487, 88e7c8b, c22a74c, b70c60b, 1d299c3, b808fd3, badcf06, ead4733, 1e936da, c972524, cb615f1, 4b5dab3
26 votes, 23 watchers
The text was updated successfully, but these errors were encountered: