在更新父对象时,使用@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]