spring-projects / spring-projects/spring-data-mongodb
Allow `DbRefResolver` to resolve bulk entities
@christophstrobl is already working on this.
Since Oct 28, 2024.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
It is relatively easy to override DbRefResolver.resolveDbRef() to return a single cached entity object
But if you want to handle the case where the property is a collection of DbRefs it is impossible. The method has no access to the list of DbRef values.
While you can override the bulkFetch() method this returns a list of Document objects - not useful if your cache contains the deserialized objects.
Currently the only solution is to extensively override the MappingMongoConverter. Since many of the methods in this class are private or package scope this requires a lot of code which will likely break with future updates.
Please add a new bulkResolveDbRef() method to DbRefResolver and call this from either MongoMappingConverter.bulkReadAndConvertDBRefs() (before bulkReadRefs()) or MappingMongoConverter.readAssociation() and passing in the full list of DbRefs to give the DbRefResolver a chance to retrieve cached entities.
Ideally DbRefResolver could return a partial list or map DbRef -> Object and MongoMappingConverter could fetch the remaining.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.