在我的代码中,我将一些基本字段放在基本抽象类中BaseEntity
:
public abstract class BaseEntity {
@Id
private long id;
public BaseEntity() {
}
public BaseEntity(long id) {
this.id = id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
所以,在子类中User
我没有定义一个id
字段:
@Entity
public class User extends BaseEntity {
private String name;
private String login;
private String gender;
private String email;
private String phoneNumber;
private Date registrationDate;
private Date lastActivityDate;
private long systemId;
public User() {
}
...Getters and Setters
}
因为它在超类中定义。我不想在每个类中创建一个id
字段,也不想在数据库BaseEntity
类中持久化。我得到一个错误:
Error:[ObjectBox] Code generation failed: No ID property found for Entity User (package:...)
如何使用带有继承的对象框?