Getting "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9" when using Hibernate/JPA in JBoss EAP 6.x/7.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
- Hibernate/JPA
- Oracle Database
- Microsoft SQL Server
Issue
I got the ERROR message caused by the foolowing exception "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9" when I use native query in my Hibernate/JPA application:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
at org.hibernate.dialect.TypeNames.get(TypeNames.java:76) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.dialect.TypeNames.get(TypeNames.java:99) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:592) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:720) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:602) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:618) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2070) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1859) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.doQuery(Loader.java:906) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.doList(Loader.java:2550) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.doList(Loader.java:2536) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.Loader.list(Loader.java:2361) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:340) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1752) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:232) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157) [hibernate-core-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268) [hibernate-entitymanager-4.2.17.SP1-redhat-1.jar:4.2.17.SP1-redhat-1]
... 259 more
Resolution
This is a bug reported in the upstream JIRA Content from hibernate.atlassian.net is not included.HHH-10183. The following JIRAs and bugzilla are raised to backport the fix to EAP 6 and EAP 7. This will be fixed in future releases:
- EAP 7.1.0: <Content from issues.jboss.org is not included.https://issues.jboss.org/browse/JBEAP-11040>, which will be incorporated in EAP 7.1.0 or later
- EAP 7.0.z: <Content from issues.jboss.org is not included.https://issues.jboss.org/browse/JBEAP-11041>, which will be incorporated in EAP 7.0.6 or later
- EAP 6.4.z: <This content is not included.https://bugzilla.redhat.com/show_bug.cgi?id=1452879>, which will be incorporated in EAP 6.4.17 or later
Until the fix is incorporated in EAP 6.x/7.x, please create a custom dialect and specify it in your persistence.xml as a workaround. For example:
-
Crate a custom dialect:
package com.example.hibernate.custom.dialect; import org.hibernate.dialect.Oracle10gDialect; public class MyCustomDialect extends Oracle10gDialect { public MyCustomDialect() { super(); registerHibernateType(Types.NVARCHAR, StringType.INSTANCE.getName()); } }Note: if you are using other dialect (for example,
org.hibernate.dialect.SQLServer2008Dialect), you should extends the class instead of extendingOracle10gDialect. -
Specify the custom dialect in your
META-INF/persistence.xml:<persistence ...> <persistence-unit name="..."> : <properties> <!-- Properties for Hibernate --> <property name="hibernate.dialect" value="com.example.hibernate.custom.dialect.MyCustomDialect"/> : </properties> </persistence-unit> </persistence>
Root Cause
- Hibernate doesn’t know how to map the JDBC type "
NVARCHAR" to a hibernate type as any dialect difines such type. - <Content from hibernate.atlassian.net is not included.https://hibernate.atlassian.net/browse/HHH-10183>
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.