From 80f61bdcff71d78d09e3bc47576efb018e770b20 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 22 Sep 2015 16:16:23 +0100 Subject: [PATCH] HHH-10139 - Fix 1 causing java.sql.SQLSyntaxErrorException: Comparisons between 'INTEGER' and 'BOOLEAN' are not supported when the column is a boolean --- .../main/java/org/hibernate/sql/Template.java | 21 +++++++++++++++---- .../org/hibernate/test/bidi/Auction.hbm.xml | 2 +- .../hibernate/test/formulajoin/Master.hbm.xml | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Template.java b/hibernate-core/src/main/java/org/hibernate/sql/Template.java index 7a6ddce353..1335caec9c 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Template.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Template.java @@ -13,6 +13,8 @@ import java.util.Locale; import java.util.Set; import java.util.StringTokenizer; +import com.sun.org.apache.xpath.internal.operations.Bool; + import org.hibernate.HibernateException; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.SQLFunction; @@ -25,6 +27,8 @@ import org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator; import org.hibernate.sql.ordering.antlr.OrderByTranslation; import org.hibernate.sql.ordering.antlr.SqlValueReference; import org.hibernate.sql.ordering.antlr.TranslationContext; +import org.hibernate.type.BooleanType; +import org.hibernate.type.Type; /** * Parses SQL fragments specified in mapping documents @@ -305,6 +309,9 @@ public final class Template { else if ( inFromClause && ",".equals(lcToken) ) { beforeTable = true; } + if ( isBoolean( token ) ) { + token = dialect.toBooleanValueString( Boolean.parseBoolean( token ) ); + } result.append(token); } @@ -712,7 +719,7 @@ public final class Template { } private static boolean isNamedParameter(String token) { - return token.startsWith(":"); + return token.startsWith( ":" ); } private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) { @@ -740,10 +747,16 @@ public final class Template { } private static boolean isIdentifier(String token) { - return token.charAt(0)=='`' || ( //allow any identifier quoted with backtick - Character.isLetter( token.charAt(0) ) && //only recognizes identifiers beginning with a letter - token.indexOf('.') < 0 + if ( isBoolean( token ) ) { + return false; + } + return token.charAt( 0 ) == '`' || ( //allow any identifier quoted with backtick + Character.isLetter( token.charAt( 0 ) ) && //only recognizes identifiers beginning with a letter + token.indexOf( '.' ) < 0 ); } + private static boolean isBoolean(String token) { + return "true".equals( token ) || "false".equals( token ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/bidi/Auction.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/bidi/Auction.hbm.xml index 4c0ba3b9f2..537da2460b 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/bidi/Auction.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/bidi/Auction.hbm.xml @@ -26,7 +26,7 @@ id - 1 + true diff --git a/hibernate-core/src/test/java/org/hibernate/test/formulajoin/Master.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/formulajoin/Master.hbm.xml index f4f0875190..64217e528f 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/formulajoin/Master.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/formulajoin/Master.hbm.xml @@ -34,7 +34,7 @@ insert="false" update="false"> - 1 + true