database - 具有一对多关系的房间数据库
问题描述
我有 2 个实体:员工和专业。每个员工都可以有一些专业。生成 POJO。
@Entity(indices = {@Index(value = {"f_name", "l_name", "birthday",
"avatarLink"}, unique = false)}, inheritSuperIndices = true)
public class Employee implements Serializable {
@PrimaryKey(autoGenerate = true)
private int employeeId;
private String f_name;
private String l_name;
private String birthday;
@Ignore
private int age;
private String avatarLink;
@Embedded
private List<Specialty> specialty;
private final static long serialVersionUID = -8824149947485321362L;
@Ignore
public Employee() {
}
public Employee(int employeeId, String f_name, String l_name, String
birthday, String avatarLink, List<Specialty> specialty) {
this.employeeId = employeeId;
this.f_name = f_name;
this.l_name = l_name;
this.birthday = birthday;
this.avatarLink = avatarLink;
this.specialty = specialty;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
And some more setters\getters...
和专业
@Entity
public class Specialty implements Serializable {
@PrimaryKey
private int specId;
private String specName;
private final static long serialVersionUID = 4288061416169200241L;
public Specialty(int specId, String specName) {
this.specId = specId;
this.specName = specName;
}
@Ignore
public Specialty() {
}
public int getSpecId() {
return specId;
}
And some more setters\getters...
我有这个错误:错误:实体和 Pojos 必须有一个可用的公共构造函数。您可以有一个空的构造函数或参数与字段匹配的构造函数(按名称和类型)。
我检查了很多问题并阅读了文档,但这对我没有帮助。谢谢
解决方案
您应该将 @Ignore 添加到 serialVersionUID 字段。在 Room 的视图中,它只是另一列。
@Ignore
private final static long serialVersionUID = 4288061416169200241L;
推荐阅读
- maven - 将 google-cloud-storage 添加到 maven - NoClassDefFoundError
- c# - 为什么 Selenium 的 Internet Explorer 驱动程序偶尔无法保持与 Web 驱动程序服务器的连接?
- c# - IIS 8.5 (Windows Server 2012 R2) 上的 Blazor 不起作用。任何想法下一步该做什么?
- binary - 在 fortran 中写一个原始的二进制无符号 32 位整数
- javascript - 将变量从php发送到js ajax
- c++ - 模板的超类
Foo 类 - r - 可以在 plyr ddply 的空分组中获取分组变量吗?
- javascript - jQuery嵌套回调“忽略”一个函数
- typescript - 打字稿代码界面
- swift - UIView setAnimationsEnabled 完成块