Hi folks,
my question is very similar to http://stackoverflow.com/questions/1118873/changing-the-type-of-an-entity-preserving-its-id, but instead i´m using InheritanceType.JOINED instead of Table_per_class.
This means i don´t to change any table, just to create a new subclass, with the same id as the superclass.
To summarize, I have a Person class and a Doctor, which extends Person and has the same id of it. I need to retrieve a Person from the database and make it a Doctor, preserving all the data from the Person entity, but creating some extra data for the Doctor one.
Trying to merge the doctor generates a new id, which is not valid for me.
Here´s what i´ve tried in first place
private Person getDoctor(Person person) {
// Person already a doctor ==> OK
if (person instanceof Doctor) {
return person;
}
// Transient Person ==> //Transient Doctor OK
if (person == null) {
return new Doctor();
}
// Creates a Doctor from the person (only setting id...),
// and merges it ==>
fails as the id changes.
Doctor doctor = new Doctor(person);
return personDAO.merge(doctor);
}
Tks.