1

有一个类似这样的类结构:

@Entity
public class A
{public ToOne<B> b;}

@Entity
public class B{public ToOne<C> с;}

@Entity
public class C{public ToOne<D> d;}

@Entity
public class D{}

它是这样填充的:

ArrayList<A> list = new ArrayList<>();
for (int i = 0; i < 10; i++){
A a = new A();
B b = new B();
C с = new C();
D d = new D();
getStore().boxFor(C).attach(c);
c.d.setTarget(d);
getStore().boxFor(B).attach(b);
b.c.setTarget(c);
getStore().boxFor(A).attach(a);
a.b.setTarget(b);
}

getStore().boxFor(A).putAll(list);

它的内容如下:

ArrayList<A> list2 = getStore().boxFor(A).getAll();
//list2.get(0).b.getTarget() is empty

问题是读完第二层是空的。

4

1 回答 1

0

尝试使用applyChangesToDb(). 文档:https ://docs.objectbox.io/relations

于 2018-09-27T11:07:37.460 回答