我有一个课,我想把课程放到ForeignCollection。在课堂上我有字段ID。我不想使用generatedId = true
,我想使用我的身份证。当我使用id = true
时,我有错误java.lang.IllegalStateException: Could not create data element in dao
,但当我使用generatedId = true
时,一切正常。我怎么解决它?
@DatabaseTable
public class UserResult {
@DatabaseField(id = true)
private int id;
...
}
PeopleResult类:(主要对象)
@DatabaseTable
public class PeopleResult extends BaseModel {
@DatabaseField(generatedId = true)
private long id;
@ForeignCollectionField(eager = false, columnName = "resultsFC", foreignFieldName = "owner")
private ForeignCollection<UserResult> resultsFC;
public ForeignCollection<UserResult> getResultsFC() {
return resultsFC;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
UserResult类(用于ForeignCollection):
@DatabaseTable
public class UserResult extends BaseModel {
public UserResult() {
}
@DatabaseField(id = true)
private long id;
@DatabaseField
private String first_name = null;
@DatabaseField(foreign = true, foreignAutoRefresh = true, foreignAutoCreate = true)
private PeopleResult owner;
public String getFirstName() {
return first_name == null ? "" : first_name;
}
public void setFirstName(String first_name) {
this.first_name = first_name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}