Not able to get query results using Room persistence

前端 未结 2 1469
既然无缘
既然无缘 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 03:58

    Change your query:

    @Query("SELECT * FROM users JOIN cars ON users.id = cars.userId")
    

    to specify the columns in the POJO class UserWithCar. The columns returned must match all the columns, and have the same column name as your POJO. You can use AS to change the column names in the query.

    @Query("SELECT userId as userId , brand as brand FROM users JOIN cars ON users.id = cars.userId")
    

    Alternatively, you can use @ColumnInfo to specify the column name mappings.

提交回复
热议问题