简体   繁体   English

错误:对象引用了未保存的瞬态实例

[英]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.

相关问题 对象引用了未保存的瞬态实例错误 - object references an unsaved transient instance error Java Spring-ManyToMany调用错误-对象引用了未保存的临时实例 - Java Spring - ManyToMany Call Error - Object references an unsaved transient instance Hibernate oneToMany - object 引用未保存的瞬态实例 - Hibernate oneToMany - object references an unsaved transient instance 对象引用了Hibernate 4.3中未保存的瞬态实例 - object references an unsaved transient instance in Hibernate 4.3 Hibernate“对象引用未保存的瞬态实例” - Hibernate “object references an unsaved transient instance” 休眠“对象引用了未保存的瞬态实例”的问题 - Hibernate “object references an unsaved transient instance” Problem 对象引用一个未保存的瞬态实例多个关系 - object references an unsaved transient instance multiple relations 如何解决对象引用未保存的瞬态实例的错误-在刷新之前保存瞬态实例? - How do I solve this error of object references an unsaved transient instance - save the transient instance before flushing? Object 引用了未保存的瞬态实例 在刷新错误之前保存瞬态实例 - Object references an unsaved transient instance save the transient instance before flushing error 保存实体时JPA错误,对象引用了未保存的瞬态实例-在刷新之前保存瞬态实例 - JPA error while saving entity, object references an unsaved transient instance - save the transient instance before flushing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM