The problem was already described in
HHH-6075
which was closed in 2012 because of some in-progress rewrites. Now (2014) the problem still exists:
MySQL defines "effective" maximum lengths of text columns. "Effective" in the case means the length in bytes, not in characters. If the database charset is utf-8 (which nowadays is default in almost all cases), mysql allows the creation of columns of 1/3 of the defined length.
The correct lengths for varchar fields are:
0...21845 -> Varchar(length) 21846...5592405 -> mediumtext more -> longtext
So the correct implementation of registerVarcharTypes is:
protected void registerVarcharTypes() {
registerColumnType( Types.VARCHAR, "longtext" );
registerColumnType( Types.VARCHAR, 16777215/3, "mediumtext" ); registerColumnType( Types.VARCHAR, 65535/3, "varchar($l)" ); registerColumnType( Types.LONGVARCHAR, "longtext" );
}
This fix is independent of any rewrite of the length-logic! It is nessecary to make hibernate's mysql(5) dialect work correctly.
The workaround in
HHH-6075
("Until then, please explicitly define column lengths on your varchars or use a custom dialect that extends/overrides MySQL5Dialect.") is invalid since it breaks database compatibility.
|