HHH-10139 - Fix <formula>1</formula> causing java.sql.SQLSyntaxErrorException: Comparisons between 'INTEGER' and 'BOOLEAN' are not supported when the column is a boolean

This commit is contained in:
Andrea Boriero 2015-09-22 16:16:23 +01:00
parent 8d3b2e723b
commit 80f61bdcff
3 changed files with 19 additions and 6 deletions

View File

@ -13,6 +13,8 @@ import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunction; 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.OrderByTranslation;
import org.hibernate.sql.ordering.antlr.SqlValueReference; import org.hibernate.sql.ordering.antlr.SqlValueReference;
import org.hibernate.sql.ordering.antlr.TranslationContext; import org.hibernate.sql.ordering.antlr.TranslationContext;
import org.hibernate.type.BooleanType;
import org.hibernate.type.Type;
/** /**
* Parses SQL fragments specified in mapping documents * Parses SQL fragments specified in mapping documents
@ -305,6 +309,9 @@ public final class Template {
else if ( inFromClause && ",".equals(lcToken) ) { else if ( inFromClause && ",".equals(lcToken) ) {
beforeTable = true; beforeTable = true;
} }
if ( isBoolean( token ) ) {
token = dialect.toBooleanValueString( Boolean.parseBoolean( token ) );
}
result.append(token); result.append(token);
} }
@ -712,7 +719,7 @@ public final class Template {
} }
private static boolean isNamedParameter(String token) { private static boolean isNamedParameter(String token) {
return token.startsWith(":"); return token.startsWith( ":" );
} }
private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) { 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) { private static boolean isIdentifier(String token) {
return token.charAt(0)=='`' || ( //allow any identifier quoted with backtick if ( isBoolean( token ) ) {
Character.isLetter( token.charAt(0) ) && //only recognizes identifiers beginning with a letter return false;
token.indexOf('.') < 0 }
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 );
}
} }

View File

@ -26,7 +26,7 @@
<one-to-one name="successfulBid" <one-to-one name="successfulBid"
property-ref="abc"> property-ref="abc">
<formula>id</formula> <formula>id</formula>
<formula>1</formula> <formula>true</formula>
</one-to-one> </one-to-one>
</class> </class>

View File

@ -34,7 +34,7 @@
insert="false" insert="false"
update="false"> update="false">
<column name="id"/> <column name="id"/>
<formula>1</formula> <formula>true</formula>
</many-to-one> </many-to-one>
</class> </class>