From b540ad43eec65b14d421c23759a8e9f48a365b03 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 9 Feb 2016 12:50:56 -0800 Subject: [PATCH] HHH-10412 : case/when in criteria always casts resulting object which fails on mysql with boolean (cherry picked from commit b1fef6c70bd3d5419982f696a1ec5310f79ff1ea) --- .../jpa/criteria/expression/CaseLiteralExpression.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/CaseLiteralExpression.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/CaseLiteralExpression.java index d56acff1ef..94fadf457e 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/CaseLiteralExpression.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/CaseLiteralExpression.java @@ -21,6 +21,13 @@ public class CaseLiteralExpression extends LiteralExpression { @Override public String render(RenderingContext renderingContext) { + // There's no need to cast a boolean value and it actually breaks on + // MySQL and MariaDB because they don't support casting to bit. + // Skip the cast for a boolean literal. + if ( getJavaType() == Boolean.class && Boolean.class.isInstance( getLiteral() ) ) { + return super.render( renderingContext ); + } + // wrapping the result in a cast to determine the node type during the antlr hql parsing phase return CastFunction.CAST_NAME + '(' + super.render( renderingContext ) +