JPA继承字段而不继承id字段

时间:2012-11-27 05:05:44

标签: java hibernate jpa

大家好

我们通常在名为CREATED_BY,LAST_UPDATED_BY,CREATION_DATE,LAST_UPDATED_DATE的每个表中放置4个字段,所以我想为什么不将它放在单个类 BaseDo 中,而不是将其继承到像这样的类中EmployeeDo 。问题是如果我用@Entity注释这个BaseDo我必须放一个我不想要的@Id字段。有没有办法实现这个目标?

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class BaseDo implements Serializable {
    private static final long serialVersionUID = 6685603264139140757L;
    @Column(name="CREATED_BY" , nullable =false )
    private String createdBy;
    @Column(name="LAST_UPDATED_BY", nullable =false )
    private String lastUpdatedBy;
    @Column(name="CREATION_DATE", nullable =false )
    private Date creationDate;
    @Column(name="LAST_UPDATED_DATE", nullable =false )
    private Date lastUpdationDate;
}

@Entity
@Table(name="EMPLOYEE")
public class EmployeeDo extends BaseDo implements Serializable {

    private static final long serialVersionUID = 4465521188079217243L;
    @Id
    @Column(name="EMPLOYEE_ID" )
    private String employeeId ;
}

非常感谢

1 个答案:

答案 0 :(得分:1)