我在尝试运行我的应用程序时得到一个An internal error occurred accessing the primary key object [class domein.PersoonSessieKey]. Internal Exception: java.lang.NoSuchMethodException: domein.PersoonSessieKey.getPersoon()
错误。我已经看过类似的问题,但我不知道我做错了什么。
我试过使用Embeddable,但因为我不知道我在做什么,这也抛出了一个错误,这让我尝试ClassId。然而现在我也得到了一个错误,我不知道是什么引起的。
实体类
@Entity
@Access(AccessType.PROPERTY)
@IdClass(PersoonSessieKey.class)
@Table(name = "PersoonSessie")
public class ClubPersoonSessie implements Serializable {
private ClubSessie sessie;
private ClubPersoon persoon;
@Id
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "SessieId")
public ClubSessie getSessie() {
return sessie;
}
public void setSessie(ClubSessie sessie) {
this.sessie = sessie;
}
@Id
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "PersoonId")
public ClubPersoon getPersoon() {
return persoon;
}
public void setPersoon(ClubPersoon persoon) {
this.persoon = persoon;
}
public ClubPersoonSessie() {
}
}
字符串
主键类
public class PersoonSessieKey implements Serializable {
private int persoonId;
private int sessieId;
public int getPersoonId() {
return persoonId;
}
public int getSessieId() {
return sessieId;
}
public PersoonSessieKey(int persoonId, int sessieId) {
this.persoonId = persoonId;
this.sessieId = sessieId;
}
public PersoonSessieKey() {
}
@Override
public int hashCode() {
int hash = 5;
hash = 89 * hash + this.persoonId;
hash = 89 * hash + this.sessieId;
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PersoonSessieKey other = (PersoonSessieKey) obj;
if (this.persoonId != other.persoonId) {
return false;
}
if (this.sessieId != other.sessieId) {
return false;
}
return true;
}
}
型
1条答案
按热度按时间cgh8pdjw1#
IdClass的属性应该与实体中用
@Id
注解的字段相匹配。这显然不是你发布的代码中的情况。应该有
domein.PersoonSessieKey.getPersoon()
(但未找到),因为您有一个用Id
注解的persoon
属性为了使它与idclass方法一起工作,