Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 继承关系未为实体指定标识符_Java_Hibernate_Inheritance - Fatal编程技术网

Java 继承关系未为实体指定标识符

Java 继承关系未为实体指定标识符,java,hibernate,inheritance,Java,Hibernate,Inheritance,如上所述,类A从类B扩展而来,B应该具有从A继承的标识符id。但是我得到了没有为实体指定标识符:com.d.e.B 我错过了什么?提前感谢。您错过了A上的@MappedSuperclass注释,以告知Hibernate/JPA必须考虑A中的属性和JPA注释 class A implements Serializable{ private static final long serialVersionUID = 1L; @Id Integer id; ...

如上所述,类
A
从类
B
扩展而来,
B
应该具有从
A
继承的标识符
id
。但是我得到了
没有为实体指定标识符:com.d.e.B


我错过了什么?提前感谢。

您错过了A上的
@MappedSuperclass
注释,以告知Hibernate/JPA必须考虑A中的属性和JPA注释

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
}