How can I get Hibernate to map nvarchar and ntext?

4.8k views Asked by At

I've inherited a project that uses SQLServer 2008 (and maybe 2005). Certain tables use nvarchar(255) and nvarchar(MAX) which Hibernate can't deal with. I've tried these proposed solutions:

How can Hibernate map the SQL data-type nvarchar(max)?

http://blog.cherouvim.com/sql-server-hbm2ddl-unicode-columns/

They don't work with nvarchar(MAX), unfortunately. I get this Exception

Caused by: org.hibernate.HibernateException: Wrong column type in MTP.dbo.Impact
edDetail for column Message. Found: ntext, expected: nvarchar(255)

The remaining problem is getting one of these solutions to work with nvarchar(MAX).

Is there a way to make Hibernate work with these unicode column types? If Hibernate won't work I can switch to another JPA provider that knows how to handle them properly.

Thanks.

1

There are 1 answers

0
Dean Schulze On BEST ANSWER

I was able to handle nvarchar(MAX) by using the @Lob annotation on the corresponding field in the Entity class while also used the SqlServerNativeDialect class in the link above.