房间删除​​查询不会删除数据库中的行

Mar*_*tin 6 android android-room android-architecture-components

我正在使用@Query删除我的Room数据库中的行,但我无法删除该记录.这是我的查询@Dao

@Dao
public interface NoteDao {

    @Insert
    void insert(final Note note);

    @Update
    void update(final Note note);

    @Query("DELETE FROM notes WHERE uid = :noteId")
    int delete(final int noteId);

    @Query("SELECT * FROM notes")
    LiveData<List<Note>> selectAll();
}
Run Code Online (Sandbox Code Playgroud)

实体类

@Entity(tableName = "notes")
public class Note {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id")
    @Expose(serialize = false, deserialize = false)
    private int mId;
    @ColumnInfo(name = "uid")
    @SerializedName("id")
    private int mUid;
    @ColumnInfo(name = "text")
    @SerializedName("text")
    private String mText;

    public Note() {
    }

    getters and setters ommited

}
Run Code Online (Sandbox Code Playgroud)

有人可以给我一个建议吗,我做错了什么?

小智 1

您可以使用@Delete注释,并且Delete方法的所有参数必须是用Entity或其集合/数组注释的类。

在你的情况下,我相信你应该使用 @Delete int delete(Note note) 或

@Delete int delete(注...注)