question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Entity's list has the same objects multiple times

See original GitHub issue

Describe 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. image

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:closed
  • Created a year ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
evanchoolycommented, May 18, 2022

@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.

0reactions
evanchoolycommented, May 18, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework referencing the same object multiple times ...
A post can only belong to one blog. By adding it to the list of posts of the second blog, the reference to...
Read more >
Working with entity instances — Pony ORM documentation
The relationships between two objects are defined by two relationship attributes. If another side of the relationship is declared as a Set ,...
Read more >
Define relationships between objects - Android Developers
In order to query the list of users and corresponding playlists, you must first model the one-to-many relationship between the two entities. To ......
Read more >
how insert same record in multiple times using entity ...
//Declare the list object here List<Student> students = new List<Student>(); for (int i = 0; i < 1000; i++) { students.Add(new Student{student_id =...
Read more >
Difference between Entity and Object - GeeksforGeeks
Entity : An entity is a real time object that is different from others. ... Every object has two components: State and Behavior....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found