我需要实现子章节并尝试以下方法:
@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
我在这里错过了什么?
我错过了添加异物:
@DatabaseField(canBeNull = true, foreign = true)
private Chapter parent;