Hi everybody, I searched all over the web and I can't seem to find any answer to my problem.
I'll explain. Suppose I have to tables on MySQL, Person and Student (this example is in order to explain my specific problem but my actual classes aren't these).
Table Person:
Columns: A and B. Primary Key: A
Table Student:
Columns: A, C and D. Primary Key: A and C (Composite Key).
So, column A in Student is a foreign key from table Person. And yes, I need C to be part of the primary key, so I can have in my table Student the same person in several rows but with a different data on C column.
As with OOP this would be Inheritance, my design would consist on two classes, one called Person and another called Student, the last one extends from Person.
Now on my
Java Application I'm using Hibernate to map this classes. I'm using table per subclass with hbm.xml files for each class.
The Person.hbm.xml would be
and now is my question, how I write Student.hbm.xml, if I need to specify that my foreign key is column A but besides the primary key is composed by A and C?
I tried:
But this doesn't work, it gives me an error like:
Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (FKBB07D2C7DB44EAC6:student[A,C])) must have same number of columns as the referenced primary key (person [A])
So I don't know how to put on the xml file that I have a composed primary key that consist on the foreign key and a column of the subclass.
Please, any help is appreciated, and please forgive my bad english. Thanks in advance.