HHH-9343 - Case/when in criteria with string literal result fails type checking

This commit is contained in:
Andrea Boriero 2015-11-27 13:09:56 +00:00
parent c040cb6718
commit 59a5a88dbd
2 changed files with 27 additions and 0 deletions

View File

@ -68,6 +68,10 @@ public class ValueHandlerFactory {
|| Double.TYPE.isInstance( value ); || Double.TYPE.isInstance( value );
} }
public static boolean isBoolean(Object value) {
return Boolean.class.isInstance( value );
}
public static class ByteValueHandler extends BaseValueHandler<Byte> implements Serializable { public static class ByteValueHandler extends BaseValueHandler<Byte> implements Serializable {
public static final ByteValueHandler INSTANCE = new ByteValueHandler(); public static final ByteValueHandler INSTANCE = new ByteValueHandler();
@SuppressWarnings({ "UnnecessaryBoxing" }) @SuppressWarnings({ "UnnecessaryBoxing" })
@ -230,6 +234,23 @@ public class ValueHandlerFactory {
} }
} }
public static class BooleanValueHandler extends BaseValueHandler<Boolean> implements Serializable {
public static final BooleanValueHandler INSTANCE = new BooleanValueHandler();
public Boolean convert(Object value) {
if ( value == null ) {
return null;
}
if ( Boolean.class.isInstance( value ) ) {
return (Boolean) value;
}
if ( String.class.isInstance( value ) ) {
return Boolean.getBoolean( (String) value );
}
throw unknownConversion( value, Boolean.class );
}
}
public static class StringValueHandler extends BaseValueHandler<String> implements Serializable { public static class StringValueHandler extends BaseValueHandler<String> implements Serializable {
public static final StringValueHandler INSTANCE = new StringValueHandler(); public static final StringValueHandler INSTANCE = new StringValueHandler();
public String convert(Object value) { public String convert(Object value) {
@ -308,6 +329,9 @@ public class ValueHandlerFactory {
if ( BigDecimal.class.equals( targetType ) ) { if ( BigDecimal.class.equals( targetType ) ) {
return (ValueHandler<T>) BigDecimalValueHandler.INSTANCE; return (ValueHandler<T>) BigDecimalValueHandler.INSTANCE;
} }
if ( Boolean.class.equals( targetType ) ) {
return (ValueHandler<T>) BooleanValueHandler.INSTANCE;
}
return null; return null;
} }
} }

View File

@ -49,6 +49,9 @@ public class LiteralExpression<T> extends ExpressionImpl<T> implements Serializa
if ( ValueHandlerFactory.isNumeric( literal ) ) { if ( ValueHandlerFactory.isNumeric( literal ) ) {
return ValueHandlerFactory.determineAppropriateHandler( (Class) literal.getClass() ).render( literal ); return ValueHandlerFactory.determineAppropriateHandler( (Class) literal.getClass() ).render( literal );
} }
else if ( ValueHandlerFactory.isBoolean( literal ) ) {
return ValueHandlerFactory.determineAppropriateHandler( (Class) literal.getClass() ).render( literal );
}
// else... // else...
final String parameterName = renderingContext.registerLiteralParameterBinding( getLiteral(), getJavaType() ); final String parameterName = renderingContext.registerLiteralParameterBinding( getLiteral(), getJavaType() );