diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java index 16bea157e5..cd34a9ca33 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java @@ -4,10 +4,6 @@ */ package org.hibernate.dialect; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.collections.Stack; @@ -41,6 +37,10 @@ import org.hibernate.sql.exec.internal.JdbcOperationQueryInsertImpl; import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.sql.exec.spi.JdbcOperationQueryInsert; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + /** * A SQL AST translator for MySQL. * @@ -81,9 +81,15 @@ public class MySQLSqlAstTranslator extends AbstractSqlA case "varchar": case "nchar": case "nvarchar": - return castTarget.getLength() == null - ? "char" - : ( "char(" + castTarget.getLength() + ")" ); + if ( castTarget.getLength() == null ) { + if ( castTarget.getJdbcMapping().getJdbcJavaType().getJavaType() == Character.class ) { + return "char(1)"; + } + else { + return "char"; + } + } + return "char(" + castTarget.getLength() + ")"; case "binary": case "varbinary": return castTarget.getLength() == null diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index 7471f02d88..d954d30936 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -1131,7 +1131,6 @@ public class FunctionTests { @Test @SkipForDialect( dialectClass = AltibaseDialect.class, reason = "Altibase cast to char does not do truncatation") - @SkipForDialect( dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "MySQL cast does not do truncatation") public void testCastFunctionWithLength(SessionFactoryScope scope) { scope.inTransaction( session -> {