[英]JPA subclass with @IdClass and no attributes
I have a subclass Entity with no @Id or @Column attribute. 我有一个没有@Id或@Column属性的子类实体。
but my subclass entity has @IdClass as follows 但是我的子类实体具有@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);
}
}
When I try to deploy my project. 当我尝试部署我的项目时。 I am getting exception from hibernate
我从休眠中得到异常
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)
complete exception is in http://pastebin.com/SnhQ1ZVQ 完整的异常位于http://pastebin.com/SnhQ1ZVQ
Hibernate is trying to find @Id class from my Entity which is not there. Hibernate试图从我不存在的Entity中找到@Id类。
How can I resolve this issue. 我该如何解决此问题。
My super class is as follows 我的超级班如下
@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
}
If I have a primary key with more than one column I use the normal @Id Property on the class I want to use as Pk. 如果我的主键具有不止一列,则在要用作Pk的类上使用常规的@Id属性。 The Id-Class is annotated with @Embeddable...
Id类使用@Embeddable注释。
example: 例:
Entity: 实体:
@Entity
public class Foo extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 1;
@EmbeddedId
private FooPK id;
//Getter, Setter...
}
EmbeddedId: EmbeddedId:
@Embeddable
public class FooPK implements Serializable {
private static final long serialVersionUID = 1;
private Integer firstId;
private Integer SecondId;
public FavoritenPK() {
}
// Setter, Getter...
} }
EDIT: I had troubles having the @Id in MappedSuperclass. 编辑:我在MappedSuperclass中有@Id遇到麻烦。 Try not to put the @Id-Property in Mapped-Superclass!
尽量不要将@ Id-Property放在Mapped-Superclass中!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.