I'm trying to figure out how to use DiscriminatorColumn when I have 1-2 different types.
Table mammal:
columns: ... order ..... species ...
Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "order", discriminatorType = DiscriminatorType.STRING)
public abstract class Mammal ...
Code:
@Entity
@DiscriminatorValue( "Carnivora" )
public class Carnivora extends Mammal
Doing this works just fine. I have no problems with any multitude of other classes. Where I run into a problem is if I want another child class that will also have the set discriminator value, but also could break down even further based on another DiscriminatorColumn.
For example..let's say I have another class:
Code:
@Entity
@DiscriminatorValue( "Canidae" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "sub_species", discriminatorType = DiscriminatorType.STRING )
public abstract class Species extends Mammal
continuing with other types from there:
Code:
@Entity
@DiscriminatorValue( "Canis lupus familiaris" )
public class Dog extends SpeciesType
Code:
@Entity
@DiscriminatorValue( "Canis lupus" )
public class Wolf extends SpeciesType
This fails as shown above with the cannot instantiate abstract class Species when I come across one that is of type Canidae. However, changing the Species to a concrete class does return the Species class back to the caller - but what I'm really after is drilling further down to the Dog or Wolf class.
I'm not sure how this should be done - other than setting the Species class apart from the Mammal class and have to make different types of calls for what it is I'm looking for.