I am using greendao 3.2 and making Entities and database. Its all working fine. But I am having trouble when creating Id property that must be Auto increment. I know How to do it in SQL but using greendao its giving me much more tough time.
I have declared my entities as normal. let me give you example.
@Entity
public class User {
// this will make your id autoincremented
@org.greenrobot.greendao.annotation.Id (autoincrement = true)
private Long Id;
private String name;
@Generated(hash = 690585871)
public User(Long Id, String name) {
this.Id = Id;
this.name = name;
}
@Generated(hash = 586692638)
public User() {
}
public Long getId() {
return this.Id;
}
public void setId(Long Id) {
this.Id = Id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
and inserting values like
user = new User();
user.setName("Hello Green Dao");
Long id = userDao.insertOrReplace(user);
but its overlapping record again and again with Id 0. Its not working as expected.
please tell me what is the reason. I have tried using Insert also but it is showing same results. Please help I am stuck into it.
I have used it as below and it is working fine.
The only difference is that you used
Id, maybe using it with capitalImade it kind of reserved word and cause this problem. Or maybe you should brief the annotation above it to@Idinstead of full package path. I know this all sounds weird, but it worth to try.