I have a set of classes Apple, Orange and Banana which all inherit from the Fruit class. I want to use the Single Table Strategy to persist all of the Fruit classes.
I understand I can use a @DiscriminatorColumn('FruitType') in the Fruit class and the @DiscriminatorValue('Apple'), @DiscriminatorValue('Orange') and @DiscriminatorValue('Banana') in the Apple, Orange and Banana classes, then make sure I have the FruitType column on the database set to either Apple, Orange or Banana.
What I would rather do if possible is have a FruitTypes table in the database to hold a list of valid @DiscriminatorValues, something like this:
Id Name ------------ 1 Apple 2 Orange 3 Banana
Then I could set up FruitTypeId on the Fruit table as a foreign key to FruitTypes and instead of using 'Apple', 'Orange' or 'Banana' I could use 1, 2 or 3.
However I would still like to keep the meaningful @DiscriminatorValues in the Apple, Orange and Banana classes i.e. @DiscriminatorValue('Apple') instead of @DiscriminatorValue('1').
Is there a value for @DiscriminatorColumn that will achieve this? Something like:
@DiscriminatorColumn('SELECT FruitType.Name FROM FruitType, Fruit WHERE FruitType.Id = Fruit.FruitTypeId')