对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例 [英] object references an unsaved transient instance - save the transient instance before flushing

查看:94
本文介绍了对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Hibernate保存对象时,我收到以下错误:

 对象引用未保存的瞬态实例 - 保存瞬态实例flushing 


解决方案

您应该包含 cascade =all(如果使用xml)或 cascade = CascadeType.ALL (如果使用注释)。 b
$ b

发生这种情况是因为您的实体中有一个集合,并且该集合中有一个或多个项目不存在于数据库中。通过指定上述选项,您可以告诉hibernate在保存它们的父级时将它们保存到数据库中。


I receive following error when I save the object using Hibernate

object references an unsaved transient instance - save the transient instance before flushing

解决方案

You should include cascade="all" (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping.

This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

这篇关于对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆