Hibernate 没有在 pojo 的父 class 中获取继承属性
Hibernate is not getting Inherited attributes in parent class of pojo
我在 Database
的每个 table 中都有一些公共字段
added_on 和 added_by
I created a pojo class:
public class CommonBean{
@Column(name="added_on")
public Date addedOn;
@Column(name="added_by")
public Integer addedBy;
//setters and getters
}
所有 pojo
class 都是 extends
那 pojo
class:
示例:
@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:
/* 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_
为什么它没有从其父 class 获取属性?
我不确定是否可行,或者我在某处出错了。
谢谢
用@MappedSuperclass注解
注解CommonBeanclass
您需要使用 @MappedSuperclass 注释 Super class。这就是你所说的 hibernate 从 super class 继承属性的方式
this will help you
我在 Database
added_on 和 added_by
I created a pojo class:
public class CommonBean{
@Column(name="added_on")
public Date addedOn;
@Column(name="added_by")
public Integer addedBy;
//setters and getters
}
所有 pojo
class 都是 extends
那 pojo
class:
示例:
@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:
/* 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_
为什么它没有从其父 class 获取属性?
我不确定是否可行,或者我在某处出错了。
谢谢
用@MappedSuperclass注解
注解CommonBeanclass您需要使用 @MappedSuperclass 注释 Super class。这就是你所说的 hibernate 从 super class 继承属性的方式 this will help you