0
室工作
我有实体:如何使用嵌套关系,
@Entity
public class A {
@PrimaryKey(autoGenerate = true)
public long id;
public A() {}
}
@Entity()
public class B {
@PrimaryKey @NonNull
public String id;
public String oneCId;
public String anotherCId;
public long aId;
public B() {}
}
@Entity
public class C {
@PrimaryKey @NonNull
public String id;
public String value;
public C() {}
}
一些的POJO:
public class AWithB {
@Embedded
public A a;
@Relation(parentColumn = "id", entityColumn = "aId")
public List<BWithC> bWithC;
public AWithB() {}
}
public class BWithC {
@Embedded
public B b;
public C oneC;
public C anotherC;
public BWithC() {}
}
与DAO:
@Query("SELECT * FROM a")
List<AWithB> getAllNow();
的问题是与@Relation对AWithB来说,因为它不能指向实体以外的任何东西。但该实体不能包含其他实体。我应该如何从DB返回整个结构?
你好Andrej,你知道如何由AwithB命令例如? –
我不确定你的意思。对于A表,您还可以使用“Order By”语句的普通查询。对于从@Relation获得的实体列表,您必须至少在Java Bean(AWithB :: getBWithCOrdered)的getter中自行完成。 –