javaobjectboxobjectbox-java

Does ObjectBox guarantee the order of an items in a ToMany collection?


The main question is: to create some explicit property in the Bar class like "externalOrder" or not.

I have some external data that must be imported into my test project. Does ObjectBox guarantee the order of an items in a ToMany<> collection after adding them to Box storage and requesting back in any moment of time in code?

class Foo {
  ToMany<Bar> relatedItems;
}

class Bar { ... }

Solution

  • ObjectBox does not guarantee the order of items in a relation. They should currently be returned ordered by ID, but there is no guarantee this won't change.