我有这个例外:
09-05 17:10:41.947: W/System.err(2144): java.sql.SQLException: Cannot update class com.mauriciogiordano.commit.database.Commitment because it doesn't have an id field
这是我的承诺类:
public class Commitment
{
@DatabaseField(generatedId = true, id = true)
private int commitmentID;
@DatabaseField
private String description;
private List<Commit> commits = null;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<Commit> getCommits() {
return commits;
}
public void setCommits(List<Commit> commits) {
this.commits = commits;
}
private void loadCommits(Context context) {
DatabaseHelper dh = new DatabaseHelper(context);
try {
Dao<Commit, Integer> dao = dh.getCommitDao();
commits = dao.queryForEq("commitmentID", commitmentID);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void newCommit(Long day, Context context) {
Commit commit = new Commit();
commit.setWhen(day);
commit.setCommitmentID(commitmentID);
commits.add(commit);
loadCommits(context);
}
public boolean hasCommitForToday(Long day, Context context) {
if(commits == null) loadCommits(context);
consecutiveDays++;
return commits.contains(day);
}
public int getCommitmentID() {
return commitmentID;
}
public void setCommitmentID(int commitmentID) {
this.commitmentID = commitmentID;
}
}
好像一切都好。
为什么我在尝试更新创建的对象时遇到此问题?
如果我没有创建commitmentID
属性,如何从对象中抓取自动创建的id
?
感谢。