not-null property references a null or transient value

前端 未结 7 1052
离开以前
离开以前 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:28

    I resolved by removing @Basic(optional = false) property or just update boolean @Basic(optional = true)

    0 讨论(0)
  • 2020-12-02 11:34

    Check the unsaved values for your primary key/Object ID in your hbm files. If you have automated ID creation by hibernate framework and you are setting the ID somewhere it will throw this error.By default the unsaved value is 0, so if you set the ID to 0 you will see this error.

    0 讨论(0)
  • 2020-12-02 11:37

    Make that variable as transient.Your problem will get solved..

    @Column(name="emp_name", nullable=false, length=30)
        private transient String empName;
    
    0 讨论(0)
  • 2020-12-02 11:41

    This could be as simple as:

    @Column(name = "Some_Column", nullable = false)
    

    but while persisting, the value of "Some_Column"is null, even if "Some_Column" may not be any primary or foreign key.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-02 11:47

    I was getting the same error but solved it finally,actually i was not setting the Object Entity which is already saved to the other entity and hence the Object value it was getting for foreeign key was null.

    0 讨论(0)
提交回复
热议问题