on his book "Spring Persistence with Hibernate" Ahmad Reza Seddighi discusses alternatives to mapping inheritance hierarchy in Hibernate (pages 102-103). On the example we have Person, Student and Teacher entities. Student and Teacher extend Person. On the example Ahmad is demonstrating "One table for each concrete class" solution for the mapping inheritance problem. Now Ahmad rises question where Address entity is added to schema. This is excat quote:
If Address has a many-to-one relationship with Person (more than one person may have the same address), then the ADDRESS table should provide a foreign key reference to all PERSON, STUDENT, and TEACHER tables, in order to establish database-level relationship, but this is not possible.
I'm confused why is that not possible. Why it would be impossible to have, lets-say "AddessID", column/foreign key for PERSON,STUDENT and TEACHER tables?
any help greatly appreaciated
On the example I'm referring to it is as You stated: "one address can be used by zero or more persons", so wouldn't that mean that PERSON table should have foreign key pointing to ADDRESS ?
lets say we have 1 row in ADDRESS:
A1;1600 Pennsylvania Avenue; Washington
and then 2 rows in PERSON:
ID;name; ADDRESS_ID (fk)
01;Barack Obama; A1
here we have 2 persons in one address, not vice versa