为了做出许多与ORMLite这两个类之间有许多关系:
@DatabaseTable(tableName值=测试1)公共类的Test1 { @ForeignCollectionField 私人ForeignCollection<&的Test2 GT; test2Collection;}@DatabaseTable(tableName值=测试2)公共类的Test2 { @ForeignCollectionField 私人ForeignCollection<&Test1的GT; test1Collection;}我面临到ORMLite在创建表的问题,不知道这个类..
之间的外键为了使这种关系我必须对每个类一样,添加一个ForeignDtabaseField:
@DatabaseTable(tableName值=测试1) 公共类的Test1 { @DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE) 私人的Test2 TEST2; @ForeignCollectionField 私人ForeignCollection<&的Test2 GT; test2Collection; } @DatabaseTable(tableName值=测试2) 公共类的Test2 { @DatabaseField(外资= TRUE,foreignAutoRefresh = TRUE) 私人测试1测试1; @ForeignCollectionField 私人ForeignCollection<&Test1的GT; test2Collection; }这似乎是一个奇怪的方式..?
解决方案为了使这种关系我必须对每个类一样,添加一个ForeignDatabaseField:
是的。你的第二个例子是正确的。没有为 ORMLite 没有其他办法能够弄清楚如何使用测试1 正在以的Test2 实例相关联,反之亦然。
请参阅文档:
- 异物
- 外国收藏
In order to make a many to many relation between these two class with ORMLite :
@DatabaseTable(tableName = "test1") public class Test1 { @ForeignCollectionField private ForeignCollection<Test2> test2Collection; } @DatabaseTable(tableName = "test2") public class Test2{ @ForeignCollectionField private ForeignCollection<Test1> test1Collection; }I'm facing to the problem that ORMLite at the tables creation, don't know about the Foreign Keys between this class..
In order to make this relation do I have to add a single ForeignDtabaseField on each class like that :
@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; }It seems to be a strange way.. ?
解决方案In order to make this relation do I have to add a single ForeignDatabaseField on each class like that:
Yes. Your second example is correct. There is no other way for ORMLite to be able to figure out how the Test1 that are associated with a Test2 instance and vice versa.
See the docs:
- Foreign objects
- Foreign collections
更多推荐
ORMLite多对多关系
发布评论