Hibernate JPA one-to-one saving child class entity

為{幸葍}努か 提交于 2019-12-03 09:31:56
Pascal Thivent

The problem here is that the @Id of EmployeeInfo is declared as being auto-generated and you're thus not supposed to set it manually (Hibernate looks at the Entity passed to persist and assumes it is already in the database because the @Id field is populated).

In other words, remove the @GeneratedValue on EmployeeInfo if you want to set the PK manually.

Note that Hibernate provides support for OneToOne association using a shared primary key in JPA 1.0 through a custom extension. See:

In JPA 2.0, derived identifiers are well supported and you can annotate OneToOne and ManyToOne associations with @Id. See:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!