Issue
This is how I am inserting data into database using Room Persistence Library:
Entity:
@Entity
class User {
@PrimaryKey(autoGenerate = true)
public int id;
//...
}
Data access object:
@Dao
public interface UserDao{
@Insert(onConflict = IGNORE)
void insertUser(User user);
//...
}
Is it possible to return the id of User once the insertion is completed in the above method itself without writing a separate select query?
Solution
Based on the documentation here (below the code snippet)
A method annotated with the @Insert annotation can return:
longfor single insert operationlong[]orLong[]orList<Long>for multiple insert operationsvoidif you don't care about the inserted id(s)
Answered By - MatPag
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.