我有一个没有@Id 或@Column 属性的子类实体。
但我的子类实体有@IdClass 如下
@Entity
@Table(name = "Employee")
@IdClass(EmployeeEntityPK.class)
public class EmployeeEntity extends AbstractEntity {
@Override
public void setName(String name) {
super.setName(name);
}
@Override
public void setLocation(String location) {
super.setLocation(location);
}
@Override
public void setEmpId(Integer empId) {
super.setEmpId(empId);
}
}
当我尝试部署我的项目时。我从休眠中得到异常
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547) [rt.jar:1.6.0_17]
at java.util.ArrayList.get(ArrayList.java:322) [rt.jar:1.6.0_17]
at org.hibernate.cfg.AnnotationBinder.getUniqueIdPropertyFromBaseClass(AnnotationBinder.java:2576)
at org.hibernate.cfg.AnnotationBinder.isIdClassPkOfTheAssociatedEntity(AnnotationBinder.java:925)
at org.hibernate.cfg.AnnotationBinder.mapAsIdClass(AnnotationBinder.java:824)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:671)
完整的例外在http://pastebin.com/SnhQ1ZVQ
Hibernate 试图从我不存在的实体中找到 @Id 类。
我该如何解决这个问题。
我的超类如下
@MappedSuperclass
public class AbstractEntity implements Serializable {
@Id
@Column(name = "empId")
private Integer empId;
@Column(name = "Name")
private String name;
@Column(name = "LOCATION")
private String location;
public Integer getEmpId() {
return empId;
}
//along with other getter setters
}