org.hibernate.annotationexception no identifier specified for entity 因为数据库的表必须要定义主键,此类没有定义主键 复合主键: 表 1-17 @IdClass 属性 属性 必需 说明 value 要指定复合主键类,请将 value 设置为所需的 Class(请参阅 @AttributeOverride)。 示例 1-37 显示了一个非嵌入的复合主键类。在该类中,字段 empName 和 birthDay 的名称和类型必须对应于实体类中属性的名称和类型。示例 1-38 显示了如何使用这个非嵌入的复合主键类(使用 @IdClass 批注)配置 EJB 3.0 实体。由于实体类字段 empName 和 birthDay 在主键中使用,因此还必须使用 @Id 批注对其进行批注。 示例 1-37 非嵌入的复合主键类 public class EmployeePK implements Serializable { private String empName; private Date birthDay; public EmployeePK() { } public String getName() { return empName; } public void setName(String name) { empName = name; } public long getDateOfBirth() { return birthDay; } public void setDateOfBirth(Date date) { birthDay = date; } public int hashCode() { return (int) empName.hashCode(); } public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof EmployeePK)) return false; if (obj == null) return false; EmployeePK pk = (EmployeePK) obj; return pk.birthDay == birthDay && pk.empName.equals(empName); } } 示例 1-38 @IdClass @IdClass(EmployeePK.class) @Entity public class Employee { @Id String empName; @Id Date birthDay; ... }