【问题标题】:Can't create table with ForeignCollection of same type无法使用相同类型的 ForeignCollection 创建表
【发布时间】:2017-12-21 09:47:54
【问题描述】:

我需要实现子章节并尝试以下方法:

@DatabaseTable(tableName = "chapters")
public class Chapter  implements Serializable{

    private static final long serialVersionUID = 3500051084584514827L;

    @DatabaseField(generatedId = true)
    private int _id;


    @DatabaseField(canBeNull = false)
    private String name;

    @DatabaseField(canBeNull = false, foreign = true)
    private Project project;

    @ForeignCollectionField(eager = true, maxEagerForeignCollectionLevel = 2)
    public ForeignCollection<Document> documents;

    @ForeignCollectionField
    public ForeignCollection<Chapter> subChapters;

    public int getId() {
        return _id;
    }

    public String getName() {
        return name;
    }

    public Project getProject() {
        return project;
    }


    Chapter() {
    }

    public Chapter(String name, Project project) {
        this.name = name;
        this.project = project;
    }
}

但它给我抛出了一个异常:

无法创建数据库 java.sql.SQLException:外部集合类 ....models.db.Chapter for field 'subChapters' column-name 不包含类 ...models.db.Chapter 的外部字段

我在这里错过了什么?

【问题讨论】:

    标签: android dao ormlite


    【解决方案1】:

    我错过了添加异物:

    @DatabaseField(canBeNull = true, foreign = true)
    private Chapter parent;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多