SQL Server + hbm2ddl + unicode columns
Hibernate offers org.hibernate.dialect.SQLServerDialect as the dialect for SQL Server. When generating the database schema, using hbm2ddl, the string type columns do not support native characters. So the following mapping:
<property name="title" length="128" />
will produce the following SQL:
... title varchar(128) null, ...
By extending the org.hibernate.dialect.SQLServerDialect we can achieve the generation of NCHAR, NVARCHAR, and NTEXT columns instead of CHAR, VARCHAR and TEXT.
package com.foo.hibernate;
import java.sql.Types;
import org.hibernate.dialect.SQLServerDialect;
public class SQLServerNativeDialect extends SQLServerDialect{
public SQLServerNativeDialect() {
super();
registerColumnType(Types.CHAR, "nchar(1)");
registerColumnType(Types.VARCHAR, "nvarchar($l)");
registerColumnType(Types.LONGVARCHAR, "nvarchar($l)");
registerColumnType(Types.CLOB, "ntext");
}
}
All we need to do now is plug this dialect in our hibernate configuration:
<property name="hibernate.dialect"> com.foo.hibernate.SQLServerNativeDialect </property>
Related hibernate forums thread: http://forum.hibernate.org/viewtopic.php?t=972518
Related API method: http://www.hibernate.org/hib_docs/v3/api/org/hibernate/dialect/Dialect.html