I am using android room persistence library for my new project.
I want to update some field of table.
I have tried like in my Dao
-
// Method 1:
@Dao
public interface TourDao {
@Update
int updateTour(Tour tour);
}
But when I try to update using this method then it updates every field of the entity where it matches primary key value of tour object.
I have used @Query
// Method 2:
@Query("UPDATE Tour SET endAddress = :end_address WHERE id = :tid")
int updateTour(long tid, String end_address);
It is working but there will be many queries in my case because I have many fields in my entity. I want to know how can I update some field (not all) like Method 1
where id = 1; (id is the auto generate primary key).
// Entity:
@Entity
public class Tour {
@PrimaryKey(autoGenerate = true)
public long id;
private String startAddress;
private String endAddress;
//constructor, getter and setter
}