Not able to get query results using Room persistence

前端 未结 2 1477
既然无缘
既然无缘 2021-02-08 03:17

I am developing an Android app using the Room persistence library. I have a User and a Car entity

@Entity(tableName = \"users\")
public class User {

    @Primar         


        
2条回答
  •  [愿得一人]
    2021-02-08 04:13

    Columns returned by the query: id, name, id, userId, brand. Fields in com.foodtec.roomdemo.data.models.UserWithCar: user_id, user_name, car_id, car_userId, car_brand.

    Error indicates that, columns returned by query is different from Pojo class. It should be the same. Alternatively you can map your Pojo variable to column name using @ColumnInfo annotation.

    For example,

    @PrimaryKey
    @NonNull
    @ColumnInfo(name = "user_id")
    private int id;
    

    This way, id will be mapped to user_id.

提交回复
热议问题