我想使用ORM注释来应用我的对象关系,但我似乎找不到使用ormLite注释正确执行此操作的方法,因为我不能在android上使用jpa,我想,但是有人这样做了,如果没有,有人能告诉我如何在Android上导入jpa与orm一起使用吗?
@DataBaseTable(tableName="some_object")
public Class SomeObject{
@DatabaseField(id=true)
private Long id;
@DatabaseField(foreign= true,foreignAutoCreate=true, foreignAutoRefresh=true)
private List<ReferencedObject> referencedObjects;
}
@DataBaseTable(tableName="referenced_object")
public Class ReferencedObject{
@DatabaseField(id=true)
private Long id;
}
答案 0 :(得分:4)
听起来你想要一个ForeignCollection
而不是List
以下是代码:
@DataBaseTable(tableName="some_object")
public Class SomeObject{
@DatabaseField(id=true)
private Long id;
@ForeignCollectionField
private ForeignCollection< ReferencedObject> referencedObjects;
}
///////////////////////////
@DataBaseTable(tableName="referenced_object")
public Class ReferencedObject{
@DatabaseField(id=true)
private Long id;
@DatabaseField(foreign=true)
private SomeObject obj;
}