This blog is mainly about Java...

Friday, July 4, 2008

Generating InnoDB engine and UTF-8 for MySQL using hibernate

I found these blogs:


They had the same problem as me, on how to generate InnoDB engine and UTF-8 for MySQL through hibernate.

This is the solution for doing it:

In persistence.xml or hibernate.cfg.xml (depending on what you are using), you add this line to get InnoDB as engine.

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>


<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect">

if you are using MySQL 4.x.

To get utf8 as default charset, you have to create the database as default charset utf8 and hibernate will do that automatically for you.

create database foo default charset utf8;

No comments: