JPA / Hibernate共享主键和@OneToOne映射

时间:2018-06-29 15:27:52

标签: java hibernate jpa

在更新父对象时,使用@OneToOne映射和共享主键插入子对象时是否可以?

public class Project{
 @Id
 @SequenceGenerator(name = "projectsIdSeq", sequenceName = "PROJECTS_ID_SEQ", allocationSize = 1)
 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "projectsIdSeq")
 private Long id;

 @OneToOne(cascade = CascadeType.ALL)
 @JoinColumn(name = "ID", referencedColumnName = "PROJECT_ID")
 @PrimaryKeyJoinColumn
 private PlanningStageInfo planningStageInfo;
}


public class PlanningStageInfo{
 @Id
 @Column(name = "PROJECT_ID")
 private Long projectId;

 @NotAudited
 @JsonIgnore
 @MapsId
 @OneToOne(mappedBy = "planningStageInfo")
 private Project project;
}

当我尝试在不使用PlanningStageInfo的情况下更新Project时,我会变得步履蹒跚

Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [ge.msda.buildtbilisi.model.PlanningStageInfo.project]

0 个答案:

没有答案