大家好
我们通常在名为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 ;
}
非常感谢
答案 0 :(得分:1)
你应该使用@MappedSuperclass
请检查
http://docs.oracle.com/javaee/5/api/javax/persistence/MappedSuperclass.html