Hibernate: the null-null property refers to a null value or a transition value

I have 2 classes: Msg and Task , which are 1-to-1.

If I try to save an Msg instance without installing a Task instance for it, I get.

 org.hibernate.PropertyValueException: not-null property references a null or transient value: entity3.Msg.task 

How to enable saving Msg without a task? I have this in the mapping file for Msg, but that doesn't help

 <many-to-one class="entity3.Task" fetch="select" name="task" not-null="false"> <column name="TaskID" not-null="true" unique="true"/> </many-to-one> 

Thanks in advance!

+4
source share
1 answer

Try changing the display as shown below.

 <many-to-one class="entity3.Task" fetch="select" name="task" column="TaskID" not-null="false"> </many-to-one> 

The problem may be that you have not-null="true" in the column definition tag. Read more about sleeping mappings here.

+5
source

Source: https://habr.com/ru/post/1382915/


All Articles