簡體   English   中英

一對多雙向關系導致的異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM