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]





I've tried,but I'm getting exception
– Tsotne
Jun 29 at 15:30






@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.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined

Opening a url is failing in Swift