2017-03-02 85 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