Entity's list has the same objects multiple times
See original GitHub issueDescribe the bug
I have a class marked with @Entity
, and it has a list, that has 3 other elements, containing different data.
Example data structure:
{
"_id": "trio",
"_t": "SaveData",
"position": [0.2, 1.0, 2.2],
"elements": [
{
"_t": "ChildData",
"position": [4.0, -1.0, 2.2]
},
{
"_t": "ChildData",
"position": [2.0, -1.0, 4.0]
},
{
"_t": "ChildData",
"position": [-3.5, 0.0, 3.5]
}
]
}
Java entity code:
@Entity("saved_stuff")
public class SaveData {
@Id
public final String saveName;
public final double[] position;
public final List<ChildData> elements;
public SaveData(String saveName, double[] position, List<ChildData> elements) {
this.saveName = saveName;
this.position = position;
this.elements = elements;
}
@Entity
public static class ChildData {
public final double[] child_position;
public final List<ChildData> child_elements;
public ChildData(double[] child_position, List<ChildData> child_elements) {
this.child_position = child_position;
this.child_elements = child_elements;
}
}
}
After using datastore.save(saveData)
, the object appears in the MongoDB database correctly (using Studio3T I have checked, the data contains the corrent values).
After querying the object, the elements
list contains the same ChildData
object 3 times, instead of 3 separate objects containing different values. This is incorrect.
To Reproduce I do the following to query the object:
Datastore datastore = ...;
SaveData data = datastore.find(SaveData.class).filter(Filters.eq("_id", "trio")).first();
Using a debugger, i can determine that in the stored data, the elements
list contains the same object 3 times.
Expected behavior
I expected the elements
list to contain the 3 elements that i have saved previously.
Please complete the following information:
- Server Version: 5.0.8
- Driver Version: 4.2.2
- Morphia Version: 2.2.6
Issue Analytics
- State:
- Created a year ago
- Comments:13 (6 by maintainers)
@MrGazdag I’ve confirmed the issue on 2.2.6 and that the fix is in 2.2.7. My last comment was for @WeeHorse and not on your issue specifically. I’ve been waiting feedback on one particular issue to confirm a fix there but I’ll just push 2.2.7 to get you the fixes you need and address the other with a later release if necessary.
I just pushed 2.2.7. It should be on central as soon as the sync finishes. Give it an hour or two and you should be set.