外部字段类没有id字段

时间:2015-02-26 19:21:51

标签: java android ormlite

我在下面的实体中遇到错误(可能是因为One To Many之间的关系),但我看不出如何解决这个问题。

课程:

@ForeignCollectionField(eager = true)
Collection<Grade> grades;

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

@DatabaseField(columnName = "LABEL", canBeNull = false)
private String label;

@DatabaseField(columnName = "COEFFICIENT", canBeNull = false, defaultValue = "1")
private float coefficient;

等级:

@DatabaseField(columnName = "ID_COURSE", canBeNull = false, foreign = true, foreignAutoRefresh = true)
Course course;

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

@DatabaseField(columnName = "DATE", canBeNull = false)
private Date date;

@DatabaseField(columnName = "GRADE", canBeNull = false, defaultValue = "1")
private float grade;

启动应用程序并尝试从数据库中获取数据时:

  

外地字段类课程没有id字段

1 个答案:

答案 0 :(得分:4)

Course类必须有id字段

@DatabaseField(generatedId = true, columnName = "ID")
Long id;

或将您现有的字段ID设为id:

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