大家好
我们通常在每个名为 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 ;
}
多谢