继承关系:实体未指定标识符。

3
class A implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    Integer id;
    ...
    // constructor getter and setter 
}

@Entity
class B extends A{
    private static final long serialVersionUID = 1L;
    @Column
    String name;
    @Column
    String age;
    ...
    //constructors, getters and setters
}

正如您在上面看到的,类A继承自类BB应该从A继承标识符id。但是我得到了No identifier specified for entity: com.d.e.B的错误提示。
请问我错过了什么?谢谢。
2个回答

9
你没有在A类上使用@MappedSuperclass注解,这个注解告诉Hibernate/JPA去识别A类中的属性和JPA注释。请尽快添加该注解。

0
在这个例子中,@MapperSuperclass 将会起作用。
如果你有实体关系(一对多、多对一等),A类应该被定义为一个实体,并且应该使用 @Inheritance 注解。
我之前也遇到了同样的错误("No identifier specified for entity"),因为我的 A 类有 @Inheritance 注解但没有 @Entity 注解。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接