Reopen: registerVarcharTypes in MySQL5Dialect creates varchar for up to a length of 65535


The problem was already described in 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:

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 ("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.


MySQL >5.1


Michael Wyraz
July 17, 2014, 2:57 PM

The behaviour of mysql is described in
According to this it really would make sense to use varchar only up to 255 (or less) characters because the maximum row size is 65535 - where varchar counts but text not. So an improvement of the above would be:

Steve Ebersole
October 27, 2015, 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see

Steve Ebersole
October 28, 2015, 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.




Michael Wyraz

Fix versions




Suitable for new contributors

Yes, likely

Requires Release Note


Pull Request





Affects versions