I have a class SocPatient.java with a corresponding table Soc_Patient and a hibernate mapping file SocPatient.hbm.xml.
I extended this class in order to add two non-persisted booleans (which I only need to keep around for JSPs) in the following fashion:
Code:
public class SocPatientChild extends SocPatient {
private static final long serialVersionUID = ....;
private boolean validationErrorsPresent;
private boolean conclusionErrorsPresent;
...
}
, and then remapped all formerly used SocPatients to use SocPatientChild wherever needed.
Now when I run the application, I keep getting MappingExceptions on SocPatientChild when a previous calls to save the SocPatients were being executed.
I tried a few different things:
1) created a SocPatientChild.hbm.xml mapped to table Soc_Patient with the same content as SocPatient.hbm.xml (failed with some other exception)
2) upcasted SocPatientChild to SocPatient before attempting the SAVE
e.g. (SocPatient) socPatientChild
3) got desperate and tried cloning (made no difference!)
In the end, I managed to solve the problem by using a combination of upcasting and copy constructor, BUT I WONDER IF THERE'S A BETTER WAY:
Code:
public class SocPatientChild extends SocPatient {
...
public SocPatient getSocPatient(){
SocPatient temp = new SocPatient(this);
return temp;
}
}
where the SocPatient copy constructor is:
public class SocPatient implements PatientResult,Serializable,java.lang.Cloneable{
...
public SocPatient(SocPatient toCopy) {
if (toCopy !=null){
this.admissionDate = toCopy.getAdmissionDate();
... manually copied everything else...
}
}
}
Thanks for any help,
-melina