给定这个类:
@MappedSuperclass
public abstract class AbstractEntity {
int id;
public void setId(int id) { this.id = id; }
public int getId() { return id; }
// other mappings
}
我想定义一个实体:
@Entity
public class SomeEntity extends AbstractEntity {
@Override
@Id // or @OneToOne etc.
public int getId() { return id; }
}
但这会在 SomeEntity 上出现“未指定标识符”(或“无法确定类型”)错误而失败。如果我从超类中删除吸气剂,它就可以工作。我不能做这个覆盖策略吗?为什么不,或者如果是 - 如何?
添加
@AttributeOverride(name = "id", column = @Column(name = "ID"))
到子类不会改变错误。