Reputation: 862
How to replace existed object by id in the room? For example, I have User with id 7 and name John. Then I change name to Bob. How to update or replace it by id in the room?
Upvotes: 0
Views: 1293
Reputation: 1732
You can use REPLACE strategy on conflict and declare insert method this way:
@Dao
interface UserDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertUser(user: User)
}
Upvotes: 0
Reputation: 814
Use the update annotation in your Dao, it would update based on the primary key (id in your case)
@Update()
void updateUser(User user);
Upvotes: 2