Hello I have a Subclass which needs to cover multiple Discriminator Values.
something like:
@DiscriminatorValue(value = "ACT","DNR","ATT" )
would do me perfect.
we have existing data where several discriminators can be mapped to one class (as they are similar types of what our system will consider the same thing)
Annotation Type DiscriminatorValueSpecifies the value of the discriminator column for entities of the given type. The DiscriminatorValue annotation can only be specified on a concrete entity class.
However, Hibernate does not support mixing <subclass> , <joined-subclass> and <union-subclass> mappings under the same root <class> element.
Only SINGLE_TABLE inheritance hierarchies require a discriminator column and values. JOINED hierarchies can use a discriminator to make some operations more efficient, but do not require one. TABLE_PER_CLASS hierarchies have no use for a discriminator.
You can use DiscriminatorFormula:
// Base class
@DiscriminatorFormula("case when value in ('ACT','DNR','ATT') then 1
when 'OTH' then 2 else 3 end")
// Subclass
@DiscriminatorValue("1") // maps to ACT, DNR, ATT
A subclass has exactly 1 discriminator value.
You can add additional subclasses under the existing subclass for the extra discriminator values. Subclasses need not have additional properties or behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With