-
Notifications
You must be signed in to change notification settings - Fork 1.1k
MappingMongoConverter eagerly fetches and converts lazy DbRef to change them afterwards by proxies [DATAMONGO-1287] #2204
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
Comments
Jordi Llach Fernandez commented I found this issue when preparing the tests for https://jira.spring.io/browse/DATAMONGO-1271 |
Christoph Strobl commented good catch Jordi Llach Fernandez. Thanks! |
Jordi Llach Fernandez commented Hi Christoph, And by the way I think that this bug is the reason why in https://jira.spring.io/browse/DATAMONGO-1332 a stackoverflow error is thrown no matter if DBRefs are lazy or not because both are eagerly fetched. J |
Jordi Llach Fernandez commented When DBRef(lazy=true) are resolved in The point is that That's the reason why in my PR I modified how the |
Jordi Llach Fernandez commented Another thing that is banging my head is how you avoid the double fetch of NON lazy DBRef
Why are you checking if the property is there with the object Thanks! |
Christoph Strobl commented thanks Jordi Llach Fernandez true - totally overlooked the fact with the accessor - removing the accessor seems to be a good idea. |
Jordi Llach Fernandez commented About the usage of lazy dbref as a constructor arg, that decision is up to the SpringData team for sure, but I encourage you to add a side note about it to the docs. |
Christoph Strobl commented Jordi Llach Fernandez, I just wanted to let you know that we've altered the lazy |
Jordi Llach Fernandez commented Thanks for the feedback. I really appreciate it |
Jordi Llach Fernandez opened DATAMONGO-1287 and commented
The problem occurs whenever an association against a document contains an annotation
@DBRef(lazy=true)
, AND this association is defined as a parameter in the constructor of the parent document.If the association is not defined as a parameter in the constructor everything works fine because
MappingMongoConverter
will use an instance ofConvertingPropertyAccessor
to inject those proxies where needed later, in the "associations" phase.MappingMongoConverter.read(MongoPersistentEntity<S>, DBObject, ObjectPath)
creates aMongoDbPropertyValueProvider
which is passed as a parameter to theEntityInstantiator
in order to load and convert the constructor parameters of each document. These constructor parameters are retrieved in theEntityInstantiator
one by one throughMongoDbPropertyValueProvider
's methodgetParameterValue(Parameter)
, if the parameter does not have any SpEL expression the call flow goes down toMongoDbPropertyValueProvider.getPropertyValue(MongoPersistentProperty)
which will useMappingMongoConverter.readValue(Object, TypeInformation<?>, ObjectPath)
to retrieve the value of the parameter, BUT this method ALWAYS resolves the DBRef (no matter if it's lazy or not).The issue is not visible by inspecting the returned object because the "association phase" in
MappingMongoConverter.read(MongoPersistentEntity<S>, DBObject, ObjectPath)
does not skip association properties already set before, and thus it fetches and converts AGAIN DBRef and sets proxies to lazy DBRef properties already resolved making the bug "invisible"Issue Links:
DATAMONGO-1271 Provide read lifecycle events when loading DBRefs
("is depended on by")
DATAMONGO-1319 Lazily loaded DBRef fields fail to resolve DBRefs contained within
DATAMONGO-2004 Lazily resolve DBRefs during constructor creation of the enclosing entity
Referenced from: pull request #335
Backported to: 1.8.2 (Gosling SR2), 1.7.3 (Fowler SR3)
2 votes, 3 watchers
The text was updated successfully, but these errors were encountered: