object references an unsaved transient instance - save the transient instance before flushing
发布日期:2021-10-24 14:20:40 浏览次数:8 分类:技术文章

本文共 1073 字,大约阅读时间需要 3 分钟。

异常1:not-null property references a null or transient value
解决方法:将“一对多”关系中的“一”方,not-null设置为false
(参考资料:http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)
异常2:org..TransientObjectException: object references an unsaved transient instance
解决方法:cascade="save-update,persist"
(参考资料:http://www.laliluna.de/254.html)
异常3:org.hibernate.QueryException: could not resolve property
解决方法:"from Category category where category.userID = :userID"修改为"from Category category whereuserID = :userID"或者"from Category category where category.user.id = :userID"
(参考资料:http://www.laliluna.de/277.html)
异常4:could not initialize proxy - the owning Session was closed
解决方法:设置lazyfalse

(参考资料:http://forum.springframework.org/showthread.?t=27993)

org..TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:

这主要是在ManyToOne级联操作时遇到,比如new了一个新对象,在未保存之前将它保存进了一个新new的对象(也即不是持久态)。

解决办法是在保存或更新之前把这个对象查出来(这样就是一个持久态)。

解决办法是将many-to-one的级联设为:cascade="save-update,persist"

转载于:https://www.cnblogs.com/archermeng/p/7537457.html

转载地址:https://blog.csdn.net/weixin_30791095/article/details/97994287 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:HibernateUtil工具类
下一篇:thinkphp整合系列之tcpdf类生成pdf文件

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月16日 10时26分43秒