Android房间数据库查询没有returnid列

Android Room database query does not return id column

问题是查询returns除'id'

以外的所有列

我使用 fts4,在文档中它说:

FTS-enabled tables always use a primary key of type INTEGER and with the column name "rowid". If your FTS-table-backed entity defines a primary key, it must use that type and column name.

这是我的实体 class:

@Fts4
@Entity(tableName = "projects")
public class Project {

    @ColumnInfo(name = "rowid")
    @PrimaryKey(autoGenerate = true)
    private int id;
    private String name;
    @ColumnInfo(name = "start_date")
    private String startDate;
    @ColumnInfo(name = "end_date")
    private String endDate;
    private String description;
    @ColumnInfo(name = "icon_path")
    private String iconPath;
    private long budget;


public Project(String name, String startDate, String endDate, String description, String iconPath, long budget) {
    this.name = name;
    this.startDate = startDate;
    this.endDate = endDate;
    this.description = description;
    this.iconPath = iconPath;
    this.budget = budget;
}


public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getStartDate() {
    return startDate;
}

public void setStartDate(String startDate) {
    this.startDate = startDate;
}

public String getEndDate() {
    return endDate;
}

public void setEndDate(String endDate) {
    this.endDate = endDate;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getIconPath() {
    return iconPath;
}

public void setIconPath(String iconPath) {
    this.iconPath = iconPath;
}

public long getBudget() {
    return budget;
}

public void setBudget(long budget) {
    this.budget = budget;
}

这是我的简单查询:

@Query("SELECT * FROM projects")
public LiveData<List<Project>> getAllProjectsI);

我收到警告:

app.aarsham.projeno.data.Model.Project has some fields [rowid] which are not returned by the query. If they are not supposed to be read from the result, you can mark them with @Ignore annotation. You can suppress this warning by annotating the method with @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). Columns returned by the query: name, start_date, end_date, description, icon_path, budget. Fields in app.aarsham.projeno.data.Model.Project: rowid, name, start_date, end_date, description, icon_path, budget.

和一个错误:

The columns returned by the query does not have the fields [id] in app.aarsham.projeno.data.Model.Project even though they are annotated as non-null or primitive. Columns returned by the query: [name,start_date,end_date,description,icon_path,budget]

有人可以帮忙吗?

使用 FTS 时,即使您使用 select * 到 select 所有行,也必须在查询中显式包含行“rowid”。

基本上,查询应该像 @Query("SELECT *, `rowid ` FROM projects")