[英]Why can I not override and annotate a getter method for entity mapping?
Given this class: 给定此类:
@MappedSuperclass
public abstract class AbstractEntity {
int id;
public void setId(int id) { this.id = id; }
public int getId() { return id; }
// other mappings
}
I want to define an entity: 我想定义一个实体:
@Entity
public class SomeEntity extends AbstractEntity {
@Override
@Id // or @OneToOne etc.
public int getId() { return id; }
}
But this fails with a "No identifier specified" (or a "Could not determine type for") error on SomeEntity. 但这失败,并在SomeEntity上出现“未指定标识符”(或“无法确定类型”)错误。 If I remove the getter from the superclass it works.
如果我从超类中删除吸气剂,它将起作用。 Can't I do this override strategy?
我不能执行此替代策略吗? Why not, or if yes - how?
为什么不呢?或者,如果可以,怎么办?
Adding 新增中
@AttributeOverride(name = "id", column = @Column(name = "ID"))
to the subclass does not change the error. 子类不会更改错误。
For you to create an entity class there are requirements that the class must meet. 要创建实体类,必须满足该类的要求。 Ex.
例如 must have a public/private constructor.
必须具有公共/私有构造函数。
Here is the list of requirements: 以下是要求列表:
http://docs.oracle.com/javaee/5/tutorial/doc/bnbqa.html http://docs.oracle.com/javaee/5/tutorial/doc/bnbqa.html
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.