Hello
Hibernate version:3.1
Mapping documents:Annotation
Name and version of the database you are using:MySql 4.5
I designed my database to be multilanguage, something like this:
table Patient_Info (id, admit_date, status, type, discharge_date)
table Patient_info_locale (patient_id, locale_id, name, family)
[name and family in second table will be inserted in different languages]
at first, I create a class for each and made a master/detail relation between them. but it made many problems for other programmers. using this strategy is very hard. because you always should challenge with the collections and there are many tables in the databse like this one. i want my programmers work with only one class not a class with a collection. I mean if I need some info from a patient I use PatientInfoLocale class and access to all attribute of patient with advantages of inheritance. I am detested using PatientInfo class and then load its collection (eg. patientInfo.getPatientInfoLocales() )
in my opinion, both patient_info and patient_info_locale are identical conceptually. so I decided to use joined inheritance strategy.
now, It buffled me. because in this strategy the subtype has the same primary key in the super type. so , for example, if the information of a patient being inserted in two different language (for example English and Russian) the primary key constraint will violated and insertion will failed.
what will happen on locale_id?
is there any other way than inheritance to solve this problem? for exmple consider these classes:
Code:
@Entity
@Table(name="patient_info")
public class PatientInfo implements Serializable {
@Id
private long id;
//rest of the codes
}
@Entity
@Table(name="patient_info_locale")
@IdClass(PatientInfoLocalePk.class)
public class PatientInfoLocale extends PatientInfo {
@Id
private long id;
@Id
private int localeId;
//rest of the codes
}
but in second table there is no field of parent table (except id as a foreign key)
how can I use inheritance advantages in this situation?
please help me out.
thank you so much in advance.