[英]org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property (hibernate+postgres)
I'm using hibernate 5.3.11 with SpringDataJpa and PostgreSQL and I get "org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [packagename.ClassB.classA]" when trying to update a complex entity ClassC.我正在使用带有 SpringDataJpa 和 PostgreSQL 的 hibernate 5.3.11,当我尝试更新一个复杂的时,我得到“org.hibernate.id.IdentifierGenerationException:试图从空一对一属性 [packagename.ClassB.classA] 分配id”实体类 C.
Relationship:关系:
Java entities: 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;
}
Short Answer: I used SpringBoot ver.2.1.8.简短回答:我使用了 SpringBoot ver.2.1.8。 Updating to 2.2.1 helped.
更新到 2.2.1 有所帮助。 Long answer here Post-upgrade, @MapsId is throwing an error when saving an existing entity, but otherwise works fine
长答案在这里升级后,@MapsId 在保存现有实体时抛出错误,但其他方面工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.