Top Description Methods
org.hibernate.annotations

public @Interface DiscriminatorFormula

extends Annotation
Annotations
@Target:TYPE
@Retention:RUNTIME
Imports
jakarta.persistence.DiscriminatorType, java.lang.annotation.Retention, .Target

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 jakarta.persistence.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;
    ...
}
Authors
Emmanuel Bernard, Steve Ebersole
See Also
Formula, DialectOverride.DiscriminatorFormula

Method Summary

Modifier and TypeMethod and Description
public DiscriminatorType
discriminatorType()

The type of value returned by the formula.

public String
value()

The formula string.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

discriminatorTypeback to summary
public DiscriminatorType discriminatorType()

The type of value returned by the formula.

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

valueback to summary
public String value()

The formula string.