Skip to content

MappingMongoConverter eagerly fetches and converts lazy DbRef to change them afterwards by proxies [DATAMONGO-1287] #2204

Closed
@spring-projects-issues

Description

@spring-projects-issues

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 of ConvertingPropertyAccessor to inject those proxies where needed later, in the "associations" phase.

MappingMongoConverter.read(MongoPersistentEntity<S>, DBObject, ObjectPath) creates a MongoDbPropertyValueProvider which is passed as a parameter to the EntityInstantiator in order to load and convert the constructor parameters of each document. These constructor parameters are retrieved in the EntityInstantiator one by one through MongoDbPropertyValueProvider's method getParameterValue(Parameter), if the parameter does not have any SpEL expression the call flow goes down to MongoDbPropertyValueProvider.getPropertyValue(MongoPersistentProperty) which will use MappingMongoConverter.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

Metadata

Metadata

Labels

in: mappingMapping and conversion infrastructuretype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions