Hibernate 5.3, SQL Server varchar(max) text displayed as Chinese characters

After upgrading from WildFly 10 to 14 which means upgarde from Hibernate 5.1 to Hibernate 5.3.6 i have problem with some text values stored by SQL Server. It displays it as chinese characters instead of the actual text.


The problem is on columns with type varchar(max). Changing to column type to nvarchar(max) resolves the issue.

In management studio the text looks fine. Im a new user so i cant put here a second screenshot.

The mapping is :

   @Column(name = "INTRO")
   private String intro;

Setup is:
Windows 10 or CentOS 7 in docker
Java 8
WIldFly 14
SQL Server driver 7.0.0.jre8 (but on earlier verions was the same)
SQL Server 2012 on Windows up to SQL 2017 on linux

Seems like an internal change in hibernate between 5.1 and 5.3. Bug?

i could subclass this dialect and change mapping for varchar(max) to nvarchar(max) but i would rather stay on the stock dialect

This is a classic case of an encoding issue. If you are displaying using a different encoding than the one you used when saving the date, a problem like this can occur.

In terms of Hibernate changes, I don’t think there’s anything that could trigger this change. You said you upgraded Wildfly from 10 to 14. But the issue can come from the web layer. How did you come to assume this was a Hibernate problem?

The only way to solve it is to use the same encoding across all layers: browser, web application, database.

1 Like

Hmmm, looked at this once more and it seems like a driver issue. It works ok in SQL Server JDBC Driver 6.4.0. It’s wrong on 7.0.0. Moving to the microsoft guys :wink:

1 Like

That’s the spirit. Thanks for confirming it.

1 Like