Matheus Galbero Zanetoni (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5fa1a2f...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOTJhOTdmOTEx...
) / Improvement (
https://hibernate.atlassian.net/browse/HHH-16785?atlOrigin=eyJpIjoiOTJhOT...
) HHH-16785 (
https://hibernate.atlassian.net/browse/HHH-16785?atlOrigin=eyJpIjoiOTJhOT...
) Problem with inserting and updating when using joined inheritance strategy (
https://hibernate.atlassian.net/browse/HHH-16785?atlOrigin=eyJpIjoiOTJhOT...
)
Issue Type: Improvement Assignee: Unassigned Created: 12/Jun/2023 20:16 PM Priority:
Blocker Reporter: Matheus Galbero Zanetoni (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5fa1a2f...
)
I am developing a project in Spring Boot to test how the inheritance works. I've got
three classes in it: Person, Doctor and Patient, where the last two classes extend the
first one. Only class Person has a primary key. The classes Doctor and Patient share the
same key (id_person) that is a foreign key in them. When I insert a new Patient, JPA also
inserts a new person, which is fine. But, when I try to insert a doctor and relate it to
the same person that was added along with patient in the database, JPA tries to do a
double insert, that is, it tries to insert data into doctor table and also in person
table. However, the person had already been inserted as a patient, and now I want to
insert it as a doctor. In my opinion, what JPA should do in a case like this one is to
verify in both entities if there is data. However, JPA only checks on entity doctor to see
if there is a doctor inserted, and as there isn't, it does double insert, when it
actually should do an update in entity person and an insert in entity doctor. Observation:
I am using the joined inheritance strategy, which is the best way to guarantee data
integrity. Is there a way to implement the correction I said above in a future release
version?
(
https://hibernate.atlassian.net/browse/HHH-16785#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16785#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:956085d )