为了使用 ORMLite 在这两个类之间建立多对多关系:
@DatabaseTable(tableName = "test1")
public class Test1 {
@ForeignCollectionField
private ForeignCollection<Test2> test2Collection;
}
@DatabaseTable(tableName = "test2")
public class Test2 {
@ForeignCollectionField
private ForeignCollection<Test1> test1Collection;
}
我面临创建表时 ORMLite 的问题,不知道此类之间的外键..
为了建立这种关系,我必须ForeignDatabaseField
在每个类上添加一个,如下所示:
@DatabaseTable(tableName = "test1")
public class Test1 {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private Test2 test2;
@ForeignCollectionField
private ForeignCollection<Test2> test2Collection;
}
@DatabaseTable(tableName = "test2")
public class Test2 {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private Test1 test1;
@ForeignCollectionField
private ForeignCollection<Test1> test2Collection;
}
这似乎是一种奇怪的方式?