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
This commit is contained in:
Gavin King 2024-12-11 12:37:40 +01:00
parent 6cfcee5e4b
commit b8a6097f5b
1 changed files with 13 additions and 13 deletions

View File

@ -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() ) ) {
else {
switch ( discriminator.getType().getName() ) {
case "character":
throw new AnnotationException( "Entity '" + name
+ "' has a discriminator of character type and must specify its '@DiscriminatorValue'" );
}
else if ( "integer".equals( discriminator.getType().getName() ) ) {
case "integer":
// TODO: pretty nasty, should we just deprecate/disallow this?
persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
}
else {
break;
default:
persistentClass.setDiscriminatorValue( name ); //Spec compliant
}
}
}
else {
persistentClass.setDiscriminatorValue( discriminatorValue );
persistentClass.setDiscriminatorValue( discriminatorValueAnn.value() );
}
}