Context: Java8 application, Spring MongoDB 1.9.1
I've got a collection containing entities of A, and another collection containing entities of B. In my domain model, Entity A has a collection of B as DBRef like this
class A {
@DBRef
List<B> myBs;
}
Moreover, I have registered two AbstractMongoEventListeners, one for A and another one for B. If I fetch a document of type A or B directly via MongoTemplate.findById(), the onAfterConvert() method is triggered alright. However, if I just fetch A, I'd expect that the onAfterConvert method is triggered also for each item B in the DBRef'ed list of A. Actually, it is not.
I hazard a guess that this works as designed, on the other side I don't the see the reason why onAfterConvert shouldn't work for any entity/document being loaded from the DB.
Long story short, I need to do some post processing for all items of B after A has been loaded. Does anyone have an elegant solution for this?
No clue, if there are better ways to solve this, but this works for me:
Overwrite the resolveDbRef() method in an extended DefaultDbRefResolver and pass it your own MappingMongoConverter when creating the bean.
Other answers/recommendations welcome