Description
Good afternoon, I am currently doing a project where I am using an "aggregation" to do a $lookup and a $unwind to get the data from a DBRef with lazy=true
. I am doing this as I need the data from one attribute inside another attribute.
@Aggregation(pipeline = {
"{ '$lookup': {" +
"'from': 'exerciseBatteries'," +
"'localField': 'exerciseBattery.$id'," +
"'foreignField': '_id'," +
"'as': 'exerciseBattery'} }",
"{'$unwind': {path: '$exerciseBattery'} }",
"{'$match': {'exerciseBattery.subject.$id': { $in: ?0} } }"
})
This correctly returns me a list with objects of the class annotated with the @Document
tag and with the attribute marked as a DBRef as an instance with the correct data, but this data is inside the CGLIB$CALLBACK_0 field. This data is fully accessible and there is no problem with it except when I try to store the class with the DBRef in my database.
What I understand should happen is that it should store the object with the reference (DBRef) without problem, however it returns me the following exception:
Caused by: org.springframework.data.mapping.MappingException: Cannot create a reference to an object with a NULL id.
This is because the fields of the class referenced by the DBRef are all set to null, not the ones inside CGLIB$CALLBACK_0, which do not generate any problem, but the fields of the class itself.
Couldn't the data of CGLIB$CALLBACK_0 be copied in those fields to avoid the error or make that when using "save" in a repository it uses, instead, the data of the DGLIB$CALLBACK_0 field?
I would find it quite useful, plus, this operation works perfectly with lazy = false
since no proxy is created and the fields are filled in naturally as with any other class