Hibernate:非空属性引用空值或瞬态值
我有 2 个类:Msg
和 Task
,它们是一对一的。
如果我尝试保存 Msg 实例而不为其设置任务实例,我会得到。
org.hibernate.PropertyValueException: not-null property references a null or transient value: entity3.Msg.task
如何在没有任务的情况下启用保存消息?我在 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>
提前致谢!
I have 2 classes: Msg
and Task
that are 1-to-1.
If i try to save Msg instance without setting Task instance for it i get.
org.hibernate.PropertyValueException: not-null property references a null or transient value: entity3.Msg.task
How do i enable saving Msg without Task? i have this in mapping file for Msg but its not helping
<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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试如下修改您的映射,
问题可能是因为您在
column
定义标记处有一个not-null="true"
。请阅读此处了解更多信息关于休眠映射。Try modifying your mapping as below,
The problem could be because you are having a
not-null="true"
at thecolumn
definition tag. Read here more about hibernate mappings.