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 <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-31 13:55:50 +01:00
parent 3c793c7a30
commit a389f771bf
1 changed files with 5 additions and 2 deletions

View File

@ -268,9 +268,12 @@ public class MySQLDialect extends Dialect {
case NUMERIC -> columnType( DECIMAL ); // it's just a synonym
// MySQL strips space characters from any value stored in a char column, which
// is especially pathological in the case of storing characters in char(1)
case CHAR -> "varchar($l)";
// on MySQL 8, the nchar/nvarchar types use a deprecated character set
case NCHAR -> "char($l) character set utf8mb4";
case NVARCHAR -> "varchar($l) character set utf8mb4";
case NCHAR, NVARCHAR -> "varchar($l) character set utf8mb4";
// the maximum long LOB length is 4_294_967_295, bigger than any Java string
case BLOB -> "longblob";