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