![](/img/trans.png)
[英]Hibernate merge org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property
[英]org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property (hibernate+postgres)
我正在使用帶有 SpringDataJpa 和 PostgreSQL 的 hibernate 5.3.11,當我嘗試更新一個復雜的時,我得到“org.hibernate.id.IdentifierGenerationException:試圖從空一對一屬性 [packagename.ClassB.classA] 分配id”實體類 C.
關系:
Java實體:
@Data
@Entity
@EqualsAndHashCode(exclude = {"classA"})
public class ClassA {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "classC_id")
private ClassC classC;
@OneToOne(mappedBy = "classA", cascade = CascadeType.ALL)
private ClassB classB;
}
@Data
@Entity
public class ClassB {
@Id
private Long id;
@OneToOne
@JoinColumn(name = "id")
@MapsId
private ClassA classA;
}
簡短回答:我使用了 SpringBoot ver.2.1.8。 更新到 2.2.1 有所幫助。 長答案在這里升級后,@MapsId 在保存現有實體時拋出錯誤,但其他方面工作正常
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.