We have the following classes
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) // optional annotation as this is default @DiscriminatorColumn(name = "apType", discriminatorType = DiscriminatorType.STRING, length = 255) @DiscriminatorValue("AP") public class ApplicationProcess { }
And this
@Entity @DiscriminatorValue("APS") public class ApplicationProcessScheme extends ApplicationProcess { }
Now I need to know at runtime if the ApplicationProcess
is of DiscriminatorValue
AP or APS
. Since this is automatically handled by jpa, I have no way of getting this value.
We are calling a method that takes an ApplicationProcess
as parameter, and I want to avoid using instanceof
to check what type it is. Would be cooler if I could do something like
applicationProcess.getApType().equals("AP");
Same column name is used for relation FK to FeatureSubtype. Use other name for discriminator or don't use discriminator at all. In Hibernate, discriminator column on joined inheritance is supported but not required. Hibernate is querying all subtables to determine correct subclass.
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.
You can map your discriminator as a read-only property:
public class ApplicationProcess { ... @Column(name = "apType", insertable = false, updatable = false) private String apType; }
I can imagine few cases where it might be helpful, but despite the reason why you need this, you could create on your abstract class method like
@Transient public String getDiscriminatorValue(){ DiscriminatorValue val = this.getClass().getAnnotation( DiscriminatorValue.class ); return val == null ? null : val.value(); }
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