HHH-6911 - Write DiscriminatorValue to DiscriminatorColumn when combined with InheritanceType#JOINED

This commit is contained in:
Steve Ebersole 2013-12-13 10:40:36 -06:00
parent faba70203a
commit 26820e8a77
2 changed files with 35 additions and 2 deletions

View File

@ -900,8 +900,32 @@ public final class AnnotationBinder {
// 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
if ( ( discriminatorColumnAnnotation != null && !mappings.ignoreExplicitDiscriminatorColumnForJoinedInheritance() )
|| ( discriminatorColumnAnnotation == null && mappings.useImplicitDiscriminatorColumnForJoinedInheritance() ) ) {
final boolean generateDiscriminatorColumn;
if ( discriminatorColumnAnnotation != null ) {
if ( mappings.ignoreExplicitDiscriminatorColumnForJoinedInheritance() ) {
LOG.debugf( "Ignoring explicit DiscriminatorColumn annotation on ", clazzToProcess.getName() );
generateDiscriminatorColumn = false;
}
else {
LOG.applyingExplicitDiscriminatorColumnForJoined(
clazzToProcess.getName(),
AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
);
generateDiscriminatorColumn = true;
}
}
else {
if ( mappings.useImplicitDiscriminatorColumnForJoinedInheritance() ) {
LOG.debug( "Applying implicit DiscriminatorColumn using DiscriminatorColumn defaults" );
generateDiscriminatorColumn = true;
}
else {
LOG.debug( "Ignoring implicit (absent) DiscriminatorColumn" );
generateDiscriminatorColumn = false;
}
}
if ( generateDiscriminatorColumn ) {
final DiscriminatorType discriminatorType = discriminatorColumnAnnotation != null
? discriminatorColumnAnnotation.discriminatorType()
: DiscriminatorType.STRING;

View File

@ -1665,4 +1665,13 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Named parameters are used for a callable statement, but database metadata indicates named parameters are not supported.", id = 456)
void unsupportedNamedParameters();
@LogMessage(level = WARN)
@Message(
id = 457,
value = "Joined inheritance hierarchy [%1$s] defined explicit @DiscriminatorColumn. Legacy Hibernate behavior " +
"was to ignore the @DiscriminatorColumn. However, as part of issue HHH-6911 we now apply the " +
"explicit @DiscriminatorColumn. If you would prefer the legacy behavior, enable the `%2$s` setting " +
"(%2$s=true)"
)
void applyingExplicitDiscriminatorColumnForJoined(String className, String overrideSetting);
}