【问题标题】:ORMLite one-to-many relationship of itselfORMLite自身的一对多关系
【发布时间】:2015-07-13 05:27:43
【问题描述】:

我有一个模型,它本身具有一对多的关系。每次我运行我的 android 应用程序时,我都会收到一个 SQLException,它指出我的字段 childRoutes 的外部集合类 Route 不包含类 Route 的外部字段。我觉得我已经在我的模型中指定了这一点,但我可能遗漏了什么?

这是我的模型,不包括 getter/setter:

public class Route implements Serializable{

@DatabaseField(id = true, canBeNull = false, columnName = "id")
private long id;

@DatabaseField(columnName = "parent", foreign = true)
private Route parent;

@ForeignCollectionField
private ForeignCollection<Route> childRoutes;

}

我在这里关注了这个问题,但我似乎仍然无法做到正确。 ORMLITE one-to-many recursive relationship

【问题讨论】:

    标签: android ormlite


    【解决方案1】:

    我似乎通过将 private ForeignCollection&lt;Route&gt; 替换为 Collection&lt;Route&gt; 解决了这个问题。如果我使用 ForeignCollection 作为类型,我不太确定为什么它不起作用,但它似乎解决了我的所有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2013-08-20
      • 1970-01-01
      • 2023-03-10
      • 2018-10-09
      • 1970-01-01
      相关资源
      最近更新 更多