My guess is you're using the MySQLDialect instead of MySQL5Dialect or its subclasses. In MySQLDialect, it registers the following varchar type mappings:
protected void registerVarcharTypes() {
registerColumnType( Types.VARCHAR, "longtext" );
registerColumnType( Types.VARCHAR, 255, "varchar($l)" );
registerColumnType( Types.LONGVARCHAR, "longtext" );
}
That means if you specify a length in the range of [0:255], it'll be mapped with the VARCHAR type and the specified length; however, if you exceed 255 then the LONGTEXT type will be used instead. Per MySQL, LONGTEXT isn't a valid data type for a PK, hence why you're observing the exception. In MySQL5Dialect and its derivatives, they register the following varchar type mappings
@Override
protected void registerVarcharTypes() {
registerColumnType( Types.VARCHAR, "longtext" );
registerColumnType( Types.VARCHAR, 65535, "varchar($l)" );
registerColumnType( Types.LONGVARCHAR, "longtext" );
}
You'll notice here, the range is specified to be between [0:65535]. Using this dialect, you'd get the correct column type mapping of VARCHAR(1024) rather than it defaulting to LONGTEXT. Are you using MySQL5? If so, please use the correct dialect. If you're not specifying a dialect and dialect resolving is picking the wrong one, please let me know specifically what version of MySQL you're using. |