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? |