From 26820e8a7768dd890fd57cef9205d7a977bdc721 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 13 Dec 2013 10:40:36 -0600 Subject: [PATCH] HHH-6911 - Write DiscriminatorValue to DiscriminatorColumn when combined with InheritanceType#JOINED --- .../org/hibernate/cfg/AnnotationBinder.java | 28 +++++++++++++++++-- .../hibernate/internal/CoreMessageLogger.java | 9 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index 27014f8e2d..45eaa63635 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 1056b56aa1..3d400ee2a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -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); }