use of jakarta.persistence.DiscriminatorColumn 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.DiscriminatorColumn 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;
}
}
use of jakarta.persistence.DiscriminatorColumn in project hibernate-orm by hibernate.
the class AnnotationBinder method processJoinedDiscriminatorProperties.
/**
* Process all discriminator-related metadata per rules for "joined" inheritance
*/
private static AnnotatedDiscriminatorColumn processJoinedDiscriminatorProperties(XClass clazzToProcess, MetadataBuildingContext context, InheritanceState inheritanceState, EntityBinder entityBinder) {
if (clazzToProcess.isAnnotationPresent(DiscriminatorFormula.class)) {
throw new MappingException("@DiscriminatorFormula on joined inheritance not supported at this time");
}
// DiscriminatorValue handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final DiscriminatorValue discriminatorValueAnnotation = clazzToProcess.getAnnotation(DiscriminatorValue.class);
final String discriminatorValue = discriminatorValueAnnotation != null ? clazzToProcess.getAnnotation(DiscriminatorValue.class).value() : null;
entityBinder.setDiscriminatorValue(discriminatorValue);
// DiscriminatorColumn handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final DiscriminatorColumn discriminatorColumnAnnotation = clazzToProcess.getAnnotation(DiscriminatorColumn.class);
if (!inheritanceState.hasParents()) {
// we want to process the discriminator column if either:
// 1) There is an explicit DiscriminatorColumn annotation && we are not told to ignore them
// 2) There is not an explicit DiscriminatorColumn annotation && we are told to create them implicitly
final boolean generateDiscriminatorColumn;
if (discriminatorColumnAnnotation != null) {
generateDiscriminatorColumn = !context.getBuildingOptions().ignoreExplicitDiscriminatorsForJoinedInheritance();
if (generateDiscriminatorColumn) {
LOG.applyingExplicitDiscriminatorColumnForJoined(clazzToProcess.getName(), AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS);
} else {
LOG.debugf("Ignoring explicit DiscriminatorColumn annotation on: %s", clazzToProcess.getName());
}
} else {
generateDiscriminatorColumn = context.getBuildingOptions().createImplicitDiscriminatorsForJoinedInheritance();
if (generateDiscriminatorColumn) {
LOG.debug("Applying implicit DiscriminatorColumn using DiscriminatorColumn defaults");
} else {
LOG.debug("Ignoring implicit (absent) DiscriminatorColumn");
}
}
if (generateDiscriminatorColumn) {
return buildDiscriminatorColumn(discriminatorColumnAnnotation != null ? discriminatorColumnAnnotation.discriminatorType() : DiscriminatorType.STRING, discriminatorColumnAnnotation, null, context);
}
} else {
if (discriminatorColumnAnnotation != null) {
LOG.invalidDiscriminatorAnnotation(clazzToProcess.getName());
}
}
return null;
}
Aggregations