Ich habe ein einfaches Modell und ich füge es in sqlite über GreenDao. Hier ist die Modellklasse:Green Dao einfügen nicht ID
@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;
}
}
Ich versuche, die Instanzen dieser Klasse ImageModel über AbstractDao.insert() Aufruf einzufügen, aber die Zeilen-ID zurückgegeben wird, ist immer 0.
ich versucht habe, mit Long
anstelle von long
für ID Feldtyp wie in dieser GitHub Diskussion vorgeschlagen: https://github.com/greenrobot/greenDAO/issues/441
aber das scheint nicht zu funktionieren. Jede Hilfe wird sehr geschätzt.