Skip to content

Commit b8a6097

Browse files
committed
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
1 parent 6cfcee5 commit b8a6097

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,27 +1596,27 @@ private void processNamedEntityGraph(NamedEntityGraph annotation) {
15961596
public void bindDiscriminatorValue() {
15971597
final DiscriminatorValue discriminatorValueAnn =
15981598
annotatedClass.getAnnotationUsage( DiscriminatorValue.class, getSourceModelContext() );
1599-
final String discriminatorValue = discriminatorValueAnn != null
1600-
? discriminatorValueAnn.value()
1601-
: null;
1602-
if ( isBlank( discriminatorValue ) ) {
1599+
if ( discriminatorValueAnn == null ) {
16031600
final Value discriminator = persistentClass.getDiscriminator();
16041601
if ( discriminator == null ) {
16051602
persistentClass.setDiscriminatorValue( name );
16061603
}
1607-
else if ( "character".equals( discriminator.getType().getName() ) ) {
1608-
throw new AnnotationException( "Entity '" + name
1609-
+ "' has a discriminator of character type and must specify its '@DiscriminatorValue'" );
1610-
}
1611-
else if ( "integer".equals( discriminator.getType().getName() ) ) {
1612-
persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
1613-
}
16141604
else {
1615-
persistentClass.setDiscriminatorValue( name ); //Spec compliant
1605+
switch ( discriminator.getType().getName() ) {
1606+
case "character":
1607+
throw new AnnotationException( "Entity '" + name
1608+
+ "' has a discriminator of character type and must specify its '@DiscriminatorValue'" );
1609+
case "integer":
1610+
// TODO: pretty nasty, should we just deprecate/disallow this?
1611+
persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
1612+
break;
1613+
default:
1614+
persistentClass.setDiscriminatorValue( name ); //Spec compliant
1615+
}
16161616
}
16171617
}
16181618
else {
1619-
persistentClass.setDiscriminatorValue( discriminatorValue );
1619+
persistentClass.setDiscriminatorValue( discriminatorValueAnn.value() );
16201620
}
16211621
}
16221622

0 commit comments

Comments
 (0)