[英]Hibernate: not-null property references a null or transient value
I have 2 classes: Msg
and Task
that are 1-to-1. 我有2个类: Msg
和Task
是1对1。
If i try to save Msg instance without setting Task instance for it i get. 如果我尝试保存Msg实例而不设置任务实例,我得到。
org.hibernate.PropertyValueException: not-null property references a null or transient value: entity3.Msg.task
How do i enable saving Msg without Task? 如何在没有任务的情况下启用保存Msg? i have this in mapping file for Msg but its not helping 我在Msg的映射文件中有这个,但它没有帮助
<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! 提前致谢!
Try modifying your mapping as below, 尝试修改您的映射,如下所示,
<many-to-one class="entity3.Task" fetch="select" name="task"
column="TaskID" not-null="false"> </many-to-one>
The problem could be because you are having a not-null="true"
at the column
definition tag. 问题可能是因为您在column
定义标记处有一个not-null="true"
。 Read here more about hibernate mappings. 在这里阅读更多关于hibernate映射的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.