我有一个简单的模型,我正在通过GreenDao将它插入到sqlite中。下面是模型类:
@Entity
public class ImageModel implements Parcelable {
public static final Creator<ImageModel> CREATOR = new Creator<ImageModel>() {
@Override
public ImageModel createFromParcel(Parcel in) {
return new ImageModel(in);
}
@Override
public ImageModel[] newArray(int size) {
return new ImageModel[size];
}
};
@Id(autoincrement = true)
private long id;
private String downloadURL;
private String pasteId;
private String storageLocation;
protected ImageModel(Parcel in) {
id = in.readLong();
downloadURL = in.readString();
pasteId = in.readString();
storageLocation = in.readString();
}
@Generated(hash = 345376828)
public ImageModel(long id, String downloadURL, String pasteId,
String storageLocation) {
this.id = id;
this.downloadURL = downloadURL;
this.pasteId = pasteId;
this.storageLocation = storageLocation;
}
@Generated(hash = 799163379)
public ImageModel() {
}
@Override
public String toString() {
return "ImageModel{" +
"id=" + id +
", downloadURL='" + downloadURL + '\'' +
", pasteId='" + pasteId + '\'' +
", storageLocation='" + storageLocation + '\'' +
'}';
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(downloadURL);
dest.writeString(pasteId);
dest.writeString(storageLocation);
}
@Override
public int describeContents() {
return 0;
}
public String getDownloadURL() {
return this.downloadURL;
}
public void setDownloadURL(String downloadURL) {
this.downloadURL = downloadURL;
}
public String getPasteId() {
return this.pasteId;
}
public void setPasteId(String pasteId) {
this.pasteId = pasteId;
}
public String getStorageLocation() {
return this.storageLocation;
}
public void setStorageLocation(String storageLocation) {
this.storageLocation = storageLocation;
}
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
}我试图通过ImageModel ()调用插入这个AbstractDao.insert类的实例,但是返回的行id始终是0。
对于id字段类型,我尝试使用Long而不是long,如本github讨论中所建议的:https://github.com/greenrobot/greenDAO/issues/441
但这似乎行不通。任何帮助都是非常感谢的。
发布于 2017-06-20 23:00:19
我也有过类似的问题。做以下工作:
long id by Long id。@annotations of GreenDAO 3),然后清理项目。ALTER TABLE或的表执行以下操作:https://stackoverflow.com/a/32429968/5286400如果需要,请参阅下一个具有类似问题的链接:https://stackoverflow.com/a/44527501/5286400
https://stackoverflow.com/questions/44093053
复制相似问题