Annotation Type DiscriminatorFormula


  • @Target(TYPE)
    @Retention(RUNTIME)
    public @interface DiscriminatorFormula
    Specifies an expression written in native SQL as the discriminator for an entity inheritance hierarchy. Must be used to annotate the root entity of the hierarchy.

    Used in place of the JPA DiscriminatorColumn.

    For example, we might declare a supertype as follows:

     @Entity
     @DiscriminatorFormula(discriminatorType = INTEGER,
                    value = "case when value1 is not null then 1 when value2 is not null then 2 end")
     public abstract class AbstractChild {
         @Id
         @GeneratedValue
         Integer id;
         ...
     }
     

    and then each concrete subclass must specify a matching discriminator value:

     @Entity
     @DiscriminatorValue("1")
     public class ConcreteChild1 extends AbstractChild {
         @Basic(optional = false)
         @Column(name = "VALUE1")
         String value;
         ...
     }
     
     @Entity
     @DiscriminatorValue("2")
     public class ConcreteChild2 extends AbstractChild {
         @Basic(optional = false)
         @Column(name = "VALUE2")
         String value;
         ...
     }
     
    See Also:
    Formula, DialectOverride.DiscriminatorFormula
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String value
      The formula string.
    • Element Detail

      • value

        String value
        The formula string.
      • discriminatorType

        DiscriminatorType discriminatorType
        The type of value returned by the formula.

        This is required, unless the expression is of type varchar or similar.

        Default:
        jakarta.persistence.DiscriminatorType.STRING