我需要检索最近插入的实体的生成id
值,因为下面添加的代码示例演示了:
如上所述,实体id
的{{1}}字段已注明Student
。
PrimaryKey(autoGenerate= true)
DAO
Student s = new Student();
s.setName("foo");
// call of other setters
appDatabase.getGenericDAO().insertStudent(s);
// Now I need to retrieve the value of generated id as we do in Hibernate by the usage of merge method
Integer id = s.getId();
答案 0 :(得分:3)
让您的@Insert
方法返回long
:
@Insert
long insertStudent(Student s);
返回值将是行的rowId
,这应该是自动生成的主键值。