Search in sources :

Example 1 with DiscriminatorType

use of jakarta.persistence.DiscriminatorType in project hibernate-orm by hibernate.

the class AnnotationBinder method processSingleTableDiscriminatorProperties.

/**
 * Process all discriminator-related metadata per rules for "single table" inheritance
 */
private static AnnotatedDiscriminatorColumn processSingleTableDiscriminatorProperties(XClass clazzToProcess, MetadataBuildingContext context, InheritanceState inheritanceState, EntityBinder entityBinder) {
    final boolean isRoot = !inheritanceState.hasParents();
    AnnotatedDiscriminatorColumn discriminatorColumn = null;
    jakarta.persistence.DiscriminatorColumn discAnn = clazzToProcess.getAnnotation(jakarta.persistence.DiscriminatorColumn.class);
    DiscriminatorType discriminatorType = discAnn != null ? discAnn.discriminatorType() : DiscriminatorType.STRING;
    DiscriminatorFormula discFormulaAnn = getOverridableAnnotation(clazzToProcess, DiscriminatorFormula.class, context);
    if (isRoot) {
        discriminatorColumn = buildDiscriminatorColumn(discriminatorType, discAnn, discFormulaAnn, context);
    }
    if (discAnn != null && !isRoot) {
        LOG.invalidDiscriminatorAnnotation(clazzToProcess.getName());
    }
    final String discriminatorValue = clazzToProcess.isAnnotationPresent(DiscriminatorValue.class) ? clazzToProcess.getAnnotation(DiscriminatorValue.class).value() : null;
    entityBinder.setDiscriminatorValue(discriminatorValue);
    DiscriminatorOptions discriminatorOptions = clazzToProcess.getAnnotation(DiscriminatorOptions.class);
    if (discriminatorOptions != null) {
        entityBinder.setForceDiscriminator(discriminatorOptions.force());
        entityBinder.setInsertableDiscriminator(discriminatorOptions.insert());
    }
    return discriminatorColumn;
}
Also used : DiscriminatorType(jakarta.persistence.DiscriminatorType) DiscriminatorColumn(jakarta.persistence.DiscriminatorColumn) DiscriminatorFormula(org.hibernate.annotations.DiscriminatorFormula) DiscriminatorValue(jakarta.persistence.DiscriminatorValue) DiscriminatorOptions(org.hibernate.annotations.DiscriminatorOptions)

Example 2 with DiscriminatorType

use of jakarta.persistence.DiscriminatorType in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getDiscriminatorColumn.

private DiscriminatorColumn getDiscriminatorColumn(ManagedType root, XMLContext.Default defaults) {
    JaxbDiscriminatorColumn element = root instanceof JaxbEntity ? ((JaxbEntity) root).getDiscriminatorColumn() : null;
    if (element != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorColumn.class);
        copyAttribute(ad, "name", element.getName(), false);
        copyAttribute(ad, "column-definition", element.getColumnDefinition(), false);
        DiscriminatorType type = element.getDiscriminatorType();
        if (type != null) {
            ad.setValue("discriminatorType", type);
        }
        copyAttribute(ad, "length", element.getLength(), false);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(DiscriminatorColumn.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbDiscriminatorColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbDiscriminatorColumn) DiscriminatorType(jakarta.persistence.DiscriminatorType) JaxbDiscriminatorColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbDiscriminatorColumn) DiscriminatorColumn(jakarta.persistence.DiscriminatorColumn) JaxbEntity(org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)

Aggregations

DiscriminatorColumn (jakarta.persistence.DiscriminatorColumn)2 DiscriminatorType (jakarta.persistence.DiscriminatorType)2 DiscriminatorValue (jakarta.persistence.DiscriminatorValue)1 DiscriminatorFormula (org.hibernate.annotations.DiscriminatorFormula)1 DiscriminatorOptions (org.hibernate.annotations.DiscriminatorOptions)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbDiscriminatorColumn (org.hibernate.boot.jaxb.mapping.spi.JaxbDiscriminatorColumn)1 JaxbEntity (org.hibernate.boot.jaxb.mapping.spi.JaxbEntity)1