Skip to content

Commit a389f77

Browse files
committed
avoid use of char(n) types on MySQL
MySQL strips trailing space characters from char(n) columns, which is very bad, because we use char(1) for storing Java char values. We can sort-of compensate for this in CharacterJavaType, but it's ugly and fragile to do it that way. Signed-off-by: Gavin King <[email protected]>
1 parent 3c793c7 commit a389f77

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,12 @@ protected String columnType(int sqlTypeCode) {
268268

269269
case NUMERIC -> columnType( DECIMAL ); // it's just a synonym
270270

271+
// MySQL strips space characters from any value stored in a char column, which
272+
// is especially pathological in the case of storing characters in char(1)
273+
case CHAR -> "varchar($l)";
274+
271275
// on MySQL 8, the nchar/nvarchar types use a deprecated character set
272-
case NCHAR -> "char($l) character set utf8mb4";
273-
case NVARCHAR -> "varchar($l) character set utf8mb4";
276+
case NCHAR, NVARCHAR -> "varchar($l) character set utf8mb4";
274277

275278
// the maximum long LOB length is 4_294_967_295, bigger than any Java string
276279
case BLOB -> "longblob";

0 commit comments

Comments
 (0)