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:
parent
6cfcee5e4b
commit
b8a6097f5b
|
@ -1596,27 +1596,27 @@ public class EntityBinder {
|
||||||
public void bindDiscriminatorValue() {
|
public void bindDiscriminatorValue() {
|
||||||
final DiscriminatorValue discriminatorValueAnn =
|
final DiscriminatorValue discriminatorValueAnn =
|
||||||
annotatedClass.getAnnotationUsage( DiscriminatorValue.class, getSourceModelContext() );
|
annotatedClass.getAnnotationUsage( DiscriminatorValue.class, getSourceModelContext() );
|
||||||
final String discriminatorValue = discriminatorValueAnn != null
|
if ( discriminatorValueAnn == null ) {
|
||||||
? discriminatorValueAnn.value()
|
|
||||||
: null;
|
|
||||||
if ( isBlank( discriminatorValue ) ) {
|
|
||||||
final Value discriminator = persistentClass.getDiscriminator();
|
final Value discriminator = persistentClass.getDiscriminator();
|
||||||
if ( discriminator == null ) {
|
if ( discriminator == null ) {
|
||||||
persistentClass.setDiscriminatorValue( name );
|
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 {
|
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 {
|
else {
|
||||||
persistentClass.setDiscriminatorValue( discriminatorValue );
|
persistentClass.setDiscriminatorValue( discriminatorValueAnn.value() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue