HHH-18515 Unrecognized discriminator value exception when running native query on entity with discriminator column
This commit is contained in:
parent
fbb1dd0c00
commit
052552f3f6
|
@ -11,7 +11,9 @@ import org.hibernate.metamodel.mapping.internal.DiscriminatorValueDetailsImpl;
|
|||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.CharacterJavaType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.java.StringJavaType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -111,6 +113,23 @@ public class MappedDiscriminatorConverter<O,R> extends DiscriminatorConverter<O,
|
|||
return notNullMatch;
|
||||
}
|
||||
|
||||
if ( value.getClass().isEnum() ) {
|
||||
final Object enumValue;
|
||||
if ( getRelationalJavaType() instanceof StringJavaType ) {
|
||||
enumValue = ( (Enum) value ).name();
|
||||
}
|
||||
else if ( getRelationalJavaType() instanceof CharacterJavaType ) {
|
||||
enumValue = ( (Enum) value ).name().charAt( 0 );
|
||||
}
|
||||
else {
|
||||
enumValue = ( (Enum) value ).ordinal();
|
||||
}
|
||||
final DiscriminatorValueDetails enumMatch = discriminatorValueToEntityNameMap.get( enumValue );
|
||||
if ( enumMatch != null ) {
|
||||
return enumMatch;
|
||||
}
|
||||
}
|
||||
|
||||
throw new HibernateException( "Unrecognized discriminator value: " + value );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue