I have a classic Hibernate @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
with @DiscriminatorFormula
. It is working fine. However, the @DiscriminatorValue
database has about 500 different values, and I need to display about 30 of them for Java classes (children), and the rest for mapping to the parent Java class.
The problem can be modeled as an example of inheritance in the Animal class.
@Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorFormula("...") public class Animal implements Serializable { ... @Column public String getName() { ... } }
So, I have about 30 subclasses of Animal defined in Java code with @DiscriminatorValue
. When Hibernate detects an unknown value for the discriminator, then it throws a WrongClassException
. However, I need to match these unknown discriminator values with a single object, the best of which is the Animal class. (I only need to use the getName () method in such cases.)
I know that one solution is to put SQL CASE in @DiscriminatorFormula
, but then I have to specify all 30 known discriminator values there (plus more when I need to add others). Therefore, I am looking for a more flexible solution.
PS This is an outdated code, so I can’t change the model.
source share