Skip to content

Provide read lifecycle events when loading DBRefs [DATAMONGO-1271] #2190

Closed
@spring-projects-issues

Description

@spring-projects-issues

Jordi Llach Fernandez opened DATAMONGO-1271 and commented

By now lifecycle events are just fired when dealing with root documents (although, by now, when using QueryDSL this support is missing, see https://jira.spring.io/browse/DATAMONGO-1185)

I think that it would be useful to trigger AfterLoad and AfterConvert events when loading related documents, through @DBRef or @DBRef(lazy = true).
I assume that one will use this kind of relation(DBRef) when the relation in itself derives from "root" entites/documents

As far as I have seen the change is minimal. I have provided a sample project on github with a custom MappingMongoConverter that fires these events.
There are two junits, one that fails because of using the default MappingMongoConverter and one that uses my customized MappingMongoConverter

The only relevant part in my CustomMappingMongoConverted starts here https://github.com/yacota/spring-data-dbrefEvents/blob/master/src/main/java/org/springframework/data/mongodb/core/convert/CustomMappingMongoConverter.java#L66
and ends here https://github.com/yacota/spring-data-dbrefEvents/blob/master/src/main/java/org/springframework/data/mongodb/core/convert/CustomMappingMongoConverter.java#L136
Just 3 methods, the rest is pure C&P

I could make a PR if this is a desired feature

UPDATE : added support to @DBRef List/Map


Reference URL: https://github.com/yacota/spring-data-dbrefEvents

Issue Links:

  • DATAMONGO-1287 MappingMongoConverter eagerly fetches and converts lazy DbRef to change them afterwards by proxies
    ("depends on")

Referenced from: pull request #322

1 votes, 4 watchers

Metadata

Metadata

Labels

in: mappingMapping and conversion infrastructuretype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions