Mapping for NVARCHAR in SqlServer not working with native queries; org.hibernate.MappingException: No Dialect mapping for JDBC type: -9

Description

Working with hibernate 5.0.2 (starting with 5.0.0) i noticed a problem using a NVARCHAR column in a sqlQuery.

Even a simple "select * from table" gives "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9".

The problem arises only when using jdbc driver from microsoft (v4.2 on java 8). Using jtds-1.3.1 the problem disappears.
The fact is that sqljdbc42.jar driver from Microsoft reports a column type -9 (that is NVARCHAR in java.sql.Types), while jtds-1.3.1 reports a value of 12 (that is VARCHAR).

I solved this adding to custom dialect:
registerHibernateType(Types.NVARCHAR, StringNVarcharType.INSTANCE.getName()); (maybe this simple fix is enough to fix sqlserver-dialects)

I also see that a similar bug is already posted for Oracle dialect at https://hibernate.atlassian.net/browse/HHH-9750
Pardon me for duping that.. I just dupe that to give more details and a test case (eclipse project without libraries to save space..)

Attachments

1
  • 13 Oct 2015, 12:15 PM

Web links

Activity

Show:

Former user May 19, 2017 at 9:16 PM

Fixed in 5.1 branch as well.

Yijun Yuan January 27, 2017 at 9:02 PM

got similar error for -15 which is NCHAR, should that be part of this?

Luca Domenichini January 19, 2017 at 3:27 PM

I think this issue https://hibernate.atlassian.net/browse/HHH-9750 should be marked as resolved too (since the PR changed Dialect class, so every dialect is fixed)

Vlad Mihalcea January 18, 2017 at 12:32 PM

Applied Pull Request upstream. , you might be interested in backporting this.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created October 13, 2015 at 12:21 PM
Updated May 22, 2017 at 6:58 PM
Resolved May 19, 2017 at 9:16 PM