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

Status

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