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;
}
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;
}
}
Aggregations