问题是查询返回了除了'id'以外的所有列
我使用fts4,在文档中说明:
启用FTS的表始终使用类型为INTEGER和列名为"rowid"的主键。如果您的FTS表支持实体定义了主键,则必须使用该类型和列名。
这是我的实体类:
@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有一些字段[rowid]没有被查询返回。如果它们不应该从结果中读取,您可以使用@Ignore注释标记它们。您可以通过在方法上注释@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)来抑制此警告。查询返回的列: name、start_date、end_date、description、icon_path、budget。app.aarsham.projeno.data.Model.Project中的字段: rowid、name、start_date、end_date、description、icon_path、budget。
还有一个错误:
查询返回的列中没有app.aarsham.projeno.data.Model.Project中的[id]字段,尽管它们被注释为非空或基元类型。查询返回的列:[name,start_date,end_date,description,icon_path,budget]
有人能帮忙解决吗?
rowid
列删除后解决了错误。希望对你有所帮助。 - hkurokawa