因为greendao插入时是判断主键是否是null,是则自增,否则插入,这也是为什么主键@Id的类型要是Long类型的原因,我遇到的问题是我的实体类做了Parcelable序列化操作
又因为使用了Long类型,这里就不能用writeLong,否则拆箱的时候会报空指针。查看Long的父类Number实现了Serializable,所以这里使用writeSerializable
@Id(autoincrement = true)//设置自增长
private Long tid;
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(this.tid);
}
protected TempUploadFileEntity(Parcel in) {
tid = (Long) in.readSerializable();
}