通过Room一对多创建@Relation

时间:2018-08-07 20:43:16

标签: android-room relation embedded-database

我试图为2个表创建“关系”:1个雇员到许多专业。 我有POJO

@Entity
public class Employee implements Serializable{
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "employee_id")
private int employeeId;
@ColumnInfo(name = "f_name")
private String f_name;
@ColumnInfo(name = "l_name")
private String l_name;
@ColumnInfo(name = "birthday")
private String birthday;
@Ignore
@ColumnInfo(name = "age")
private int age;
@ColumnInfo(name = "avatar_url")
private String avatr_url;
@Ignore
private List<Specialty> specialty;

和专业:

public class Specialty implements Serializable{

@PrimaryKey
@ColumnInfo(name = "specialty_id")
public int specialty_id;
@ColumnInfo(name = "specialty_name")
public String name;
@ColumnInfo(name = "employeeOwner_id")
public int employeeId;

我也创建了联合课程:

public class EmployeeToSpecialty {
@Embedded
public Employee employee;

@Relation(parentColumn = "employee_id", entityColumn = "specialty_id")
public List<Specialty> specialties;
}

然后我得到了错误: 该查询返回ru.alexsuvorov.employee_service.model.EmployeeToSpecialty未使用的某些列[specialty_id,specialty_name,employeeId]。 您可以在字段上使用@ColumnInfo批注指定映射。 ru.alexsuvorov.employee_service.model.EmployeeToSpecialty具有查询未返回的某些字段[employee_id,f_name,l_name,birthday,avatar_url]。如果不应从结果中读取它们,则可以使用@Ignore批注对其进行标记。您可以通过使用@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)注释该方法来禁止显示此警告。查询返回的列:Specialty_id,specialty_name,employeeId。 ru.alexsuvorov.employee_service.model.EmployeeToSpecialty中的字段:employee_id,f_name,l_name,birthday,avatar_url。

我添加了必要的列和注释,那是什么问题?

0 个答案:

没有答案