[英]Error: object references an unsaved transient instance
I am using Hibernate, and I got the following error: 我正在使用Hibernate,但出现以下错误:
org.hibernate.TransientObjectException: object references an unsaved transient instance
- save the transient instance before flushing: db.Concern
org.hibernate.TransientObjectException: object references an unsaved transient instance
- save the transient instance before flushing: db.Concern
I created an object of the Concern
entity, where I did the following: 我创建了Concern
实体的对象,在其中执行了以下操作:
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "concernId")
private Concern concern;
When using Hibernate or any other JPA provider, setting cascade = CascadeType.ALL
causes persist and update and other operations being cascaded down to child relationships. 当使用Hibernate或任何其他JPA提供程序时,设置cascade = CascadeType.ALL
导致持久性和更新以及其他操作被层叠为子关系。
In addition by default @OneToOne
relationships are FetchType.Eager
. 除了默认@OneToOne
关系FetchType.Eager
。 So you can either save concern
explicitly or you can remove fetch = FetchType.LAZY
from the annotation . 因此,您可以明确保存concern
,也可以从注释中删除fetch = FetchType.LAZY
。
You are probably saving some other object when this error is thrown. 抛出此错误时,您可能正在保存其他对象。 So before saving that object save the concern
object and then the other object. 因此,在保存该对象之前,先保存concern
对象,然后再保存其他对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.