JPA/Hibernate shared primary key and @OneToOne mapping
JPA/Hibernate shared primary key and @OneToOne mapping
Is it possible,when using @OneToOne mapping and shared primary key to insert child object,while updating Parent object?
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;
}
When I'm trying to update Project without PlanningStageInfo I'm getting eroor
Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [ge.msda.buildtbilisi.model.PlanningStageInfo.project]
@Zorglube can you give me some example?
– Tsotne
Jun 29 at 15:48
This might help stackoverflow.com/questions/3417097/…
– Ashish451
Jun 29 at 15:56
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I've tried,but I'm getting exception
– Tsotne
Jun 29 at 15:30