【问题标题】:Hibernate is not getting Inherited attributes in parent class of pojoHibernate 没有在 pojo 的父类中获取继承的属性
【发布时间】:2017-03-02 12:05:23
【问题描述】:

Database的每张表我都有一些常用字段

added_on added_by

我创建了一个 pojo 类:

public class CommonBean{

    @Column(name="added_on")
    public Date addedOn;

    @Column(name="added_by")
    public Integer addedBy;

    //setters and getters
}

所有pojo 类都是extends 那个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: 
    /* 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_ 

为什么它没有从其父类获取属性?

我不确定这是否可能,或者我在某个地方犯了错误。

谢谢

【问题讨论】:

标签: java hibernate inheritance annotations pojo


【解决方案1】:

使用@MappedSuperclass 注解来注解CommonBean 类

【讨论】:

    【解决方案2】:

    你需要用@MappedSuperclass 来注解超类。这就是你说休眠从超类继承属性的方式 this will help you

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 2020-10-29
      • 1970-01-01
      • 2013-04-06
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      • 2019-02-28
      相关资源
      最近更新 更多