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..)

Environment

Hibernate 5.0.2, Java 8, Microsoft Sql Server 2012 (or 2008), sqljdbc4.2 driver from microsoft, jtds-1.3.1 driver from sourceforge

Activity

Show:
Vlad Mihalcea
January 18, 2017, 12:32 PM

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

Luca Domenichini
January 19, 2017, 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)

Yijun Yuan
January 27, 2017, 9:02 PM

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

Gail Badner
May 19, 2017, 9:16 PM

Fixed in 5.1 branch as well.

Assignee

Vlad Mihalcea

Reporter

Luca Domenichini

Fix versions

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

Affirmative

backportDecision

None

Components

Affects versions

Priority

Major
Configure