not-null property references a null or transient value

前端 未结 7 1051
离开以前
离开以前 2020-12-02 11:15

Facing trouble in saving parent/child object with hibernate. Any idea would be highly appreciated.

org.hibernate.PropertyValueException: not-null property re         


        
7条回答
  •  时光取名叫无心
    2020-12-02 11:46

    Every InvoiceItem must have an Invoice attached to it because of the not-null="true" in the many-to-one mapping.

    So the basic idea is you need to set up that explicit relationship in code. There are many ways to do that. On your class I see a setItems method. I do NOT see an addInvoiceItem method. When you set items, you need to loop through the set and call item.setInvoice(this) on all of the items. If you implement an addItem method, you need to do the same thing. Or you need to otherwise set the Invoice of every InvoiceItem in the collection.

提交回复
热议问题