Customized MySql5Dialect for Hibernate

By default the MySqlDialect who is coming with Hibernate does MySQL not force to UTF. And by default all binary columns are mapped to “tinyblob”. That’s why I wrote my own Dialect. It is very easy to do. Just a fiew lines of code. Here is my own MySql5Dialect.

import org.hibernate.dialect.MySQL5InnoDBDialect;

import java.sql.Types;

public class MySql5Dialect extends MySQL5InnoDBDialect {

  public String getTableTypeString() {
    return " ENGINE=InnoDB DEFAULT CHARSET=utf8";
  }

  public MySql5Dialect() {
    super();
    registerColumnType( Types.BINARY, "MEDIUMBLOB" );
  }

}

You can use by adding this to your hibernate.properties files:

hibernate.dialect=org.<your_package_name>.MySql5Dialect

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: