ORMLite多对多关系

编程入门 行业动态 更新时间:2024-10-28 05:28:36
本文介绍了ORMLite多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为了做出许多与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多对多关系

本文发布于:2023-10-23 13:28:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   ORMLite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!