Using @OneToOne with @Id to share a primary key only seems to work if the getters (for the ID and relationship fields) are annotated. If the annotations are on the fields, then it fails. I don't know if this is accepted behaviour or not.
Based on [this example| http https :// websystique hellokoding .com/ hibernate/hibernate jpa -one-to-one- bidirectional-with- shared-primary-key- annotation relationship - mapping- example -with-spring-boot-maven-and-mysql /], I put together a MWE [as a github repo|https://github.com/stackfull/jpa-onetoone-sharedprimarykey-springboot-maven-h2]. The master branch uses getter annotations, the `field-annotations` branch uses field annotations. Run the app with `mvn spring-boot:run` to see it fail.
As far as I can tell, it is during the cascade merge that the link back to the parent (Book) is broken. |
|