I found out today that MS Sql server seems to handle Unicode in a
very special way. Instead of having some support a database or table
level, each Unicode column have to be created as “national”. That is be
either nchar, nvarchar or ntext.

Ms SQL Server 2005 seems to go one step further by announcing future deprecation for ntext, text and image types.

From Sql Server 2005 notes:

ntext, text, and image
data types will be removed in a future version of Microsoft SQL Server.
Avoid using these data types in new development work, and plan to
modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.”

When working with Hibernate it seems there is no dialect to handle
Unicode integration properly. You have to get down and write a custom
dialect that maps to the new data types.

You have to write your own SQLServerDialect class, it looks something like this:

[/crayon]

This class maps Hibernate’s types to SQL types, so the class will map the nvarchar(max) SQL Data Type to Hibernate’s CLOB data type.

The getTypeName method is used to return
“ntext” when Hibernate asks about the data type with code 2005 (which
looks like it’s the nvarchar(max) data type).

Finally, you need to change your hibernate persistence dialect to
this new SQLServerDialect class, which allows hibernate to translate
data types into SQL data types.

2 Responses to Hibernate, UTF-8 and SQL Server 2005
  1. I really liked your blog! It helped me alot…


[top]

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注