Room error: no viable alternative at input?

Viewed 10095

I am trying to update the table using @Query annotation of room library, below is my code ( In Dao interface ) :

@Query("UPDATE table_name SET table_name.col1 = :val1 WHERE table_name.col2 = :val2")
void updateValue(long val1, long val2);

Complete error string as below :

Error:(11, 10) error: no viable alternative at input 'UPDATE table_name SET table_name.'

Here is entity class :

@Entity(tableName = "table_name")
public class SampleTable {

    @PrimaryKey
    @ColumnInfo(name = "_id")
    private Long Id;

    @ColumnInfo(name = "col1")
    private Long column1;

    @ColumnInfo(name = "col2")
    private Long column2;

    public Long getId() {
        return Id;
    }

    public void setId(Long id) {
        Id = id;
    }

    public Long getColumn1() {
        return column1;
    }

    public void setColumn1(Long column1) {
        this.column1 = column1;
    }

    public Long getColumn2() {
        return column2;
    }

    public void setColumn2(Long column2) {
        this.column2 = column2;
    }
}

What's wrong with my code ?

3 Answers

This error could also happen in this case:

If you are passing a list, don't forget to add the parentheses enclosing your list variable, otherwise you will get the same error:

@Query("select name from mytable where name in (:myList)")
LiveData<List<String>> findNames(List<String> myList);

In my case a message was error: no viable alternative at input 'is' (and a query name was mentioned). I found that the query didn't have necessary spaces between words like here:

    "from car" +       // Add a space here.
    "where brand_id is null" +
Related