How to specify multiple discriminator columns in a single table inheritance strategy (multilevel inheritance)

I am just copying the original question from older forum - Hibernate Community • View topic - Multiple discriminator columns

Say my class hierarchy is the following, and I want to use table-per-hierarchy:


What I’d like to do is create the table CAT with discriminator columns TYPE and SUB_TYPE.

TYPE can have the values “DOMESTIC” and “WILD”.
SUB_TYPE can have the values “PERSIAN”, “MANX”, “LION” and “TIGER”.

Any suggestion how to deal with multi level inheritance situation?

Is this a legacy table structure that you want to map or are you considering to model it this way? I would recommend you use a single table inheritance, make Cat, DomesticCat and WildCat abstract, and finally use a single discriminator column. Hibernate does not really support multiple discriminator columns per level.

Thanks @beikov. You are right about discriminator columns.

I found a way using discriminator formula -
@DiscriminatorFormula("CONCAT(type, sub_type)")

Then, I could put these on different entities in the hierarchy @DiscriminatorValue("DomesticCat") or @DiscriminatorValue("DomesticCatPersian")