【问题标题】:Abstract Nesting class in ormliteormlite中的抽象嵌套类
【发布时间】:2015-07-23 05:29:50
【问题描述】:

我有一个项目,其中包含三种类型的嵌套对象,位置、类别和值列表。每个对象都是一个包含父字段和子字段的树。所以我想创建一个抽象类作为基类,我正在使用 ormlite 来保存记录。

我的抽象类如下所示:

public abstract class SelectionValue {

    @DatabaseField(generatedId = true, columnName = "_id")
    private long id;

    @DatabaseField
    private String label;

    @DatabaseField
    private int sort;

    @DatabaseField
    private long valueId;

    @ForeignCollectionField
    private Collection<SelectionValue> children;

    @DatabaseField (foreign = true, foreignAutoRefresh = true)
    private SelectionValue parent;

    // setters and gettings 
}

但是当我运行应用程序时,我从 ormlite 收到此错误:

Foreign collection SelectionValue for field 'children' column-name does not contain a
    foreign field of class Location.

有解决办法吗?

【问题讨论】:

  • SelectionValue 类是否包含字段Location?这就是外国领域的运作方式。否则,ORMLite 怎么知道某个位置有哪些子节点?

标签: java ormlite


【解决方案1】:

您孩子的数据类型错误。根据 ORMLite 手册:http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_2.html#Foreign-Collection 你的类应该是这样的:

@ForeignCollectionField
private ForeignCollection<SelectionValue> children;

【讨论】:

  • 试过了,还是不行,文档说明你可以使用 ForeignCollection 或 Collection
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-09
  • 1970-01-01
  • 2014-08-16
相关资源
最近更新 更多