Skip to content

Commit 7fadfc0

Browse files
committed
HHH-10139 - Fix <formula>1</formula> causing java.sql.SQLSyntaxErrorException: Comparisons between 'INTEGER' and 'BOOLEAN' are not supported when the column is a boolean
1 parent ab8e679 commit 7fadfc0

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

hibernate-core/src/main/java/org/hibernate/sql/Template.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.Set;
1414
import java.util.StringTokenizer;
1515

16+
import com.sun.org.apache.xpath.internal.operations.Bool;
17+
1618
import org.hibernate.HibernateException;
1719
import org.hibernate.dialect.Dialect;
1820
import org.hibernate.dialect.function.SQLFunction;
@@ -25,6 +27,8 @@
2527
import org.hibernate.sql.ordering.antlr.OrderByTranslation;
2628
import org.hibernate.sql.ordering.antlr.SqlValueReference;
2729
import org.hibernate.sql.ordering.antlr.TranslationContext;
30+
import org.hibernate.type.BooleanType;
31+
import org.hibernate.type.Type;
2832

2933
/**
3034
* Parses SQL fragments specified in mapping documents
@@ -305,6 +309,9 @@ else if ( isIdentifier(token)
305309
else if ( inFromClause && ",".equals(lcToken) ) {
306310
beforeTable = true;
307311
}
312+
if ( isBoolean( token ) ) {
313+
token = dialect.toBooleanValueString( Boolean.parseBoolean( token ) );
314+
}
308315
result.append(token);
309316
}
310317

@@ -712,7 +719,7 @@ public ColumnMapper getColumnMapper() {
712719
}
713720

714721
private static boolean isNamedParameter(String token) {
715-
return token.startsWith(":");
722+
return token.startsWith( ":" );
716723
}
717724

718725
private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) {
@@ -740,10 +747,16 @@ private static boolean isFunction(String lcToken, String nextToken, SQLFunctionR
740747
}
741748

742749
private static boolean isIdentifier(String token) {
743-
return token.charAt(0)=='`' || ( //allow any identifier quoted with backtick
744-
Character.isLetter( token.charAt(0) ) && //only recognizes identifiers beginning with a letter
745-
token.indexOf('.') < 0
750+
if ( isBoolean( token ) ) {
751+
return false;
752+
}
753+
return token.charAt( 0 ) == '`' || ( //allow any identifier quoted with backtick
754+
Character.isLetter( token.charAt( 0 ) ) && //only recognizes identifiers beginning with a letter
755+
token.indexOf( '.' ) < 0
746756
);
747757
}
748758

759+
private static boolean isBoolean(String token) {
760+
return "true".equals( token ) || "false".equals( token );
761+
}
749762
}

hibernate-core/src/test/java/org/hibernate/test/bidi/Auction.hbm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<one-to-one name="successfulBid"
2727
property-ref="abc">
2828
<formula>id</formula>
29-
<formula>1</formula>
29+
<formula>true</formula>
3030
</one-to-one>
3131
</class>
3232

hibernate-core/src/test/java/org/hibernate/test/formulajoin/Master.hbm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
insert="false"
3535
update="false">
3636
<column name="id"/>
37-
<formula>1</formula>
37+
<formula>true</formula>
3838
</many-to-one>
3939

4040
</class>

0 commit comments

Comments
 (0)