views:

23

answers:

0

Hi all,

Recently I've been considering using the DiscriminatorColumn approach to achieve entity inheritance. Eventually I've rejected this idea, because the positives from it would have been insignificant and they wouldn't have paid off.

One question still bothers me though. It comes up from the following situation. Let's say that we have an entity "Person" and a property "profession" for it. However I'm not content with the profession as a property, I want it to be an table/entity, so that I could for instance attach some characteristics to every profession which can apply to more than one profession at the same time. In the end I will have three tables - Person, Profession and SpecialFeats and the relationship between each other would be Profession:Person - 1:N and Profession:SpecialFeats - 1:N, the id of the profession being the foreign key in both the Person and the SpecialFeats table. Furthermore I would like to distinguish the Person class, which is a fairly general class into subclasses based on the profession. For instance I would like to have classes like Programmer, Salesman etc. Physically they are all the same table - the Person table, but in the persistence layer I would like them to be different classes, inherited from the Person class. Normally in this case I should use the DiscriminatorColumn "profession" in the Person table to distinguish the subclasses. In my case however, instead of having a property "profession" I have a foreign key, which is the ID of the table "Profession". My question is, would this work at all and if so, how should it be implemented correctly? Shall I use the corresponding IDs as a DiscriminatorValues or there is a better way of doing this?

Thanks, al