Facing trouble in saving parent/child object with hibernate. Any idea would be highly appreciated.
org.hibernate.PropertyValueException: not-null property re
I resolved by removing @Basic(optional = false) property or just update boolean @Basic(optional = true)
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.
Make that variable as transient.Your problem will get solved..
@Column(name="emp_name", nullable=false, length=30)
private transient String empName;
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.
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.
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.