4

I've got 2 objects with the parent holding a list of children:

@Entity
public class Parent {

    @Backlink
    public ToMany<Child> children;
    ...
}

and

@Entity
public class Child {

    ToOne<Parent> parent;
    ...
}

Then I call size() on the ToMany

parent.children.size()

And I get the following crash which I can't understand:

Caused by java.lang.IllegalStateException
ToOne object is null inside ...Child
io.objectbox.Cursor.nativeGetBacklinkEntities (Cursor.java)
io.objectbox.Cursor.getBacklinkEntities (Cursor.java:279)
io.objectbox.Box.internalGetBacklinkEntities (Box.java:623)
io.objectbox.relation.ToMany.ensureEntities (ToMany.java:172)
io.objectbox.relation.ToMany.size (ToMany.java:395)

It looks like the parent is looking at the list of children and for each one checks the link to the parent. It crashes because this link is null. I don't understand how ObjectBox would manage to get to such a situation. Any ideas?

Y. Adler
  • 41
  • 2

1 Answers1

4

Maybe its because you didn't write the No-arg constructor. So the to-one and to-many relations will not be automatically initialized by gradle.

As the crash said

ToOne object is null inside ...
Shawn Xu
  • 186
  • 1
  • 6