[英]Exception caused by one-to-many bidirectional relationship
我有两个实体关系,我相信我做得很好,但是当我尝试运行我的应用程序时,Payara 正在启动这个错误:
Caused by: Exception [EclipseLink-7154] (Eclipse Persistence Services - 2.7.4.payara-p2): org.eclipse.persistence.exceptions.ValidationException Exception Description: The attribute [retenciones] in entity class [class komp.model.ChequePropio ] 的 mappedBy 值为 [chequepropio],它在其拥有的实体 class [class komp.model.RetencionChp] 中不存在。 如果拥有实体 class 是 @MappedSuperclass,则这是无效的,您的属性应引用正确的子类。
这是导致问题的实体之一:
@Entity
@Table(name = "chequepropio", uniqueConstraints = {
@UniqueConstraint(name = "ukchequepropio", columnNames = {"idbanco", "idempresa", "idtipo", "numero"})})
public class ChequePropio implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToMany(fetch = FetchType.LAZY,mappedBy = "chequepropio")
private List<RetencionChp> retenciones;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
其他实体:
@Entity
@Table(name = "retencionchp")
public class RetencionChp implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idcheque", insertable = true, updatable = true)
private ChequePropio chequePropio;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public ChequePropio getChequePropio() {
return chequePropio;
}
public void setChequePropio(ChequePropio chequePropio) {
this.chequePropio = chequePropio;
}
}
我看不出关系中有任何错误,有人可以告诉我有什么问题吗?
提前致谢! 费尔南多
该错误是不言自明的:
实体 class [class komp.model.ChequePropio] 中的属性 [retenciones] 的 mappedBy 值为 [chequepropio],该值在其拥有的实体 ZA2F2ED4F8EBC4ABB4DZC21A29 中不存在
注意关键字chequepropio
。 您在RetencionChp
中没有chequepropio
属性。 你有一个chequePropio
代替。 注意大写的P
。 以下应该解决它( mappedBy = "chequePropio")
)。
@Entity
@Table(name = "chequepropio", uniqueConstraints = {
@UniqueConstraint(name = "ukchequepropio", columnNames = {"idbanco", "idempresa", "idtipo", "numero"})})
public class ChequePropio implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToMany(fetch = FetchType.LAZY,mappedBy = "chequePropio")
private List<RetencionChp> retenciones;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.