首页 > 解决方案 > 房间:选择查询不检索对象的属性

问题描述

我的 android 应用程序提供用户帐户。用户由以下类表示:

public class User implements Parcelable {
    @NonNull
    @ColumnInfo(name = "user_Id")
    @PrimaryKey (autoGenerate = true)
    private Long userId;
    private String displayedName;
    private String email;
    private String password;
    @ColumnInfo(name = "photo_Id")
    private Long photoId;

PhotoId 引用了 Photo :

public class Photo implements Parcelable {
    @NonNull
    @ColumnInfo(name = "photo_Id")
    @PrimaryKey(autoGenerate = true)
    private Long photoId;
    private String image;

当我保存用户帐户时,我先保存用户,然后保存照片,最后使用生成的照片 ID 更新用户。我使用这些查询:

    @Insert
    Single<Long> insert(User user);
    @Update
    Completable update (User user);
    @Insert
    Single<Long> insert(Photo photo);

根据日志,创建过程似乎 100% 成功,但是当我从数据库中检索用户时

    @Query("SELECT * FROM User WHERE email = :userEmail")
    Single<User> getUserByEmail(String userEmail);

我检索一个具有空 photoId 的用户。如果用户选择查询未创建完整的 User ,我该如何调试并查找用户 photoId 是否未在 DB por 中正确更新?


更新:问题是即使更新后用户在数据库中也没有 photId。

标签: androidandroid-room

解决方案


推荐阅读