Java Hibernate未在pojo的父类中获取继承的属性
我在Java Hibernate未在pojo的父类中获取继承的属性,java,hibernate,inheritance,annotations,pojo,Java,Hibernate,Inheritance,Annotations,Pojo,我在数据库的每个表中都有一些公共字段 添加于和添加于 我创建了一个pojo类: 所有pojo类都是扩展的pojo类: 例如: @Table(name = "employee") @Entity public class HrEmployee extends CommonBean implements java.io.Serializable{ private static final long serialVersionUID = 1L; @Id @Generated
数据库的每个表中都有一些公共字段
添加于和添加于
我创建了一个pojo类:
所有pojo
类都是扩展的pojo
类:
例如:
@Table(name = "employee")
@Entity
public class HrEmployee extends CommonBean implements java.io.Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer id;
@Column(name="first_name")
private String firstName;
@Column(name="middle_name")
private String middleName;
@Column(name="last_name")
private String lastName;
}
但当我调用hibernate标准的列表方法时。
我可以在控制台中看到生成的查询:
Hibernate:
/* criteria query */ select
this_.id as y0_,
this_.first_name as y2_,
this_.middle_name as y3_,
this_.last_name as y4_
from
hr_employee this_
为什么不从父类获取属性
我不确定这是否可能,或者我在某个地方犯了错误
谢谢用@MappedSuperclass注释CommonBean类你需要用@MappedSuperclass注释超类。这就是为什么说hibernate从超类继承属性
尝试实体继承-
Hibernate:
/* criteria query */ select
this_.id as y0_,
this_.first_name as y2_,
this_.middle_name as y3_,
this_.last_name as y4_
from
hr_employee this_