2017-03-02 48 views
0

的休眠是没有得到继承属性,我在Database每个表的一些常见领域在父类POJO

ADDED_ONadded_by

我创建了一个POJO类:

public class CommonBean{ 

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

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

    //setters and getters 
} 

而且所有pojoextendspojo类:

例如:

@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_ 

为什么它没有得到来自它的父类的属性?

我不确定这是可能的还是我在某处出错。

感谢

+0

尝试实体继承 - https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#entity-inheritance – Chaitanya

回答

0

标注CommonBean类@MappedSuperclass注解

0

你需要注释超类@MappedSuperclass。这就是你说如何从超级类继承属性休眠 this will help you