无法使用相同类型的ForeignCollection创建表

问题描述 投票:0回答:1

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

@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字段'subChapters'列名不包含类的外部字段... models.db.Chapter

我在这里错过了什么?

android dao ormlite
1个回答
0
投票

我错过了添加异物:

@DatabaseField(canBeNull = true, foreign = true)
private Chapter parent;
© www.soinside.com 2019 - 2024. All rights reserved.