我想用两个foreignCollections 持久化一个对象。但是当我尝试查询该对象时,我的 foreignId 始终为空。我已经阅读了这个答案,但它并没有真正帮助我:ORMLite 中的集合
VOPerception perception = new VOPerception();
perception.setOrientation(daoOrientation.createIfNotExists(
orientationLocalizer.getCurrentOrientation()));
ForeignCollection<VOAccessPoint> fAp =
daoPerception.getEmptyForeignCollection("accessPoints");
fAp.addAll(wifiLocalizer.getCurrentScanResultMap());
perception.setAccessPoints(fAp);
daoPerception.create(perception);
List<VOPerception> list = daoPerception.queryForAll();
此处数据已正确存储,但 VOAccessPoint 对象与父 VOPerception 对象没有链接。
这是我的两门课:
public class VOPerception {
@DatabaseField(generatedId=true)
private int per_id;
@ForeignCollectionField(eager=true)
ForeignCollection<VOAccessPoint> accessPoints;
...
}
public class VOAccessPoint{
@DatabaseField(generatedId=true)
private int ap_id;
@DatabaseField(foreign=true,columnName="apForeignPerception_id")
private VOPerception apForeignPerception;
...
}