I have a simple Model and I am inserting it into sqlite via GreenDao. Here is the model class:
@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;
}
}
I am trying to insert the instances of this ImageModel class via AbstractDao.insert() call, but the row id returned is always 0.
I have tried using Long
instead of long
for id field type as suggested in this github discussion:
https://github.com/greenrobot/greenDAO/issues/441
but this does not seems to work. Any help is much appreciated.