From b8a6097f5bef699a9380987cd2057eae787753e9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 11 Dec 2024 12:37:40 +0100 Subject: [PATCH] treat empty/blank @DiscriminatorValue literally the spec doesn't say it can't be empty, and so I think this is the most natural interpretation --- .../boot/model/internal/EntityBinder.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index 5140680888..48df4077fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -1596,27 +1596,27 @@ public class EntityBinder { public void bindDiscriminatorValue() { final DiscriminatorValue discriminatorValueAnn = annotatedClass.getAnnotationUsage( DiscriminatorValue.class, getSourceModelContext() ); - final String discriminatorValue = discriminatorValueAnn != null - ? discriminatorValueAnn.value() - : null; - if ( isBlank( discriminatorValue ) ) { + if ( discriminatorValueAnn == null ) { final Value discriminator = persistentClass.getDiscriminator(); if ( discriminator == null ) { persistentClass.setDiscriminatorValue( name ); } - else if ( "character".equals( discriminator.getType().getName() ) ) { - throw new AnnotationException( "Entity '" + name - + "' has a discriminator of character type and must specify its '@DiscriminatorValue'" ); - } - else if ( "integer".equals( discriminator.getType().getName() ) ) { - persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) ); - } else { - persistentClass.setDiscriminatorValue( name ); //Spec compliant + switch ( discriminator.getType().getName() ) { + case "character": + throw new AnnotationException( "Entity '" + name + + "' has a discriminator of character type and must specify its '@DiscriminatorValue'" ); + case "integer": + // TODO: pretty nasty, should we just deprecate/disallow this? + persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) ); + break; + default: + persistentClass.setDiscriminatorValue( name ); //Spec compliant + } } } else { - persistentClass.setDiscriminatorValue( discriminatorValue ); + persistentClass.setDiscriminatorValue( discriminatorValueAnn.value() ); } }