This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes org.hibernate.MappingException: No Dialect mapping for JDBC type: -9 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9" Watch "org.hibernate.MappingException: No Dialect mapping for JDBC type: -9" New topic
Author

org.hibernate.MappingException: No Dialect mapping for JDBC type: -9

Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Hi,

I get the above error message when I do this select (as a native query):



Here is the Java code:



The "em" is the entity manager.

Here is the stack trace:
org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:370)
org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:559)
org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:485)
org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:501)
org.hibernate.loader.Loader.getResultSet(Loader.java:1796)
org.hibernate.loader.Loader.doQuery(Loader.java:674)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
org.hibernate.loader.Loader.doList(Loader.java:2220)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
org.hibernate.loader.Loader.list(Loader.java:2099)
org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
org.apache.jsp.webclient.admin.custom.query_005fstatistics_jsp._jspService(query_005fstatistics_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
om.face.oam.AdminFilter.doFilter(AdminFilter.java:109)


What am I doing wrong here? The database is an SQL Server 2008.

Thanks
Markus
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What data types are you using in your mapped table?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Paul Sturrock wrote:What data types are you using in your mapped table?


nvarchar50. Some cells are null, many have the same content, but that shouldn't be a problem, should it?

/Markus
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

nvarchar(50) should be fine. What driver and dialect are you using?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

...also, out of curiosity, that is a very simple query. Any reason you are doing it in native SQL rather than as Criteria or as HQL? Like I say, just curious. Its probably nothing to do with your issue.
Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Paul Sturrock wrote:nvarchar(50) should be fine. What driver and dialect are you using?


The direver is sqljdbc4 (com.microsoft.sqlserver.jdbc.SQLServerDriver) and the dialect is org.hibernate.dialect.SQLServerDialect. I am also using this query:



...and that works fine.

/Markus
Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Paul Sturrock wrote:...also, out of curiosity, that is a very simple query. Any reason you are doing it in native SQL rather than as Criteria or as HQL? Like I say, just curious. Its probably nothing to do with your issue.


I have a view that is defined by the query:

This works fine:

And this doesn't (org.hibernate.MappingException: No Dialect mapping for JDBC type: -9):

I tried both SQL and HQL, no difference.
/Markus
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That is odd behaviour. JDBC Type -9 is nvarchar, and I am happily using them with Hibernate against SQL Server 2008. The only difference is I use jTDS, but the MS SQL Server driver is pretty decent these days (I'd be amazed if they had not implemented NVARCHAR). Can you show use the DDL for the table(s) you compose you view from?
Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Paul Sturrock wrote:That is odd behaviour. JDBC Type -9 is nvarchar, and I am happily using them with Hibernate against SQL Server 2008. The only difference is I use jTDS, but the MS SQL Server driver is pretty decent these days (I'd be amazed if they had not implemented NVARCHAR). Can you show use the DDL for the table(s) you compose you view from?


DDL? Is this what you mean?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes I did, but unfortunately nothing obvious shows itself from that!

I can't really think of a reason this doesn't work. Have you tried swapping to jTDS? Might be worth a go.
Markus Källander
Greenhorn

Joined: May 20, 2009
Posts: 15
Paul Sturrock wrote:Yes I did, but unfortunately nothing obvious shows itself from that!

I can't really think of a reason this doesn't work. Have you tried swapping to jTDS? Might be worth a go.


Can't change the driver. But I just discovered that when I cast the nvarchar to varchar (cast([ServerName] as varchar) as ServerName) it works fine!, So I'll go with that...

Thanks!
/Markus
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, seems a little drastic ditching Unicode support just to work round this, but its your call.

I've had a quick glance on MSDN, it looks like its only from the 2.0 version of the official driver that NVARCHAR was supported. If you can convince whoever is preventing you upgrading to change their mind I would do that.
aswini nayak
Greenhorn

Joined: Jan 24, 2012
Posts: 5


I am using this Query as follows


config.configure(new File(_hibernateConfigPath));
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();


String myquery = "select t2.name as column_name from sys.objects t1 inner join sys.columns t2 on t2.object_id = t1.object_id"+
" left join sys.indexes t3 on t3.object_id = t1.object_id and t3.is_unique = 1 left join sys.index_columns t4 on t4.object_id = t1.object_id and t4.index_id = t3.index_id and t4.column_id = t2.column_id where (upper(t1.type) = 'U' or upper(t1.type) = 'V') and upper(schema_name(t1.schema_id)) = 'dbo' and upper(t1.name) = 'TEST'";


List<Object[]> metadataList = session.createSQLQuery(myquery).list();
session.close();

I am getting org.hibernate.MappingException: No Dialect mapping for JDBC type: -9. Dont understand why? Please help!!!



Rashmi Shukla
Greenhorn

Joined: Jan 30, 2012
Posts: 1
hi... try this..


String myquery = "select cast(t2.name as varchar) column_name from sys.objects t1 inner join sys.columns t2 on t2.object_id = t1.object_id"+
" left join sys.indexes t3 on t3.object_id = t1.object_id and t3.is_unique = 1 left join sys.index_columns t4 on t4.object_id = t1.object_id and t4.index_id = t3.index_id and t4.column_id = t2.column_id where (upper(t1.type) = 'U' or upper(t1.type) = 'V') and upper(schema_name(t1.schema_id)) = 'dbo' and upper(t1.name) = 'TEST'";
aswini nayak
Greenhorn

Joined: Jan 24, 2012
Posts: 5
Thanks Rashmi it works for me but is there any other solution?
Fredy Wilches
Greenhorn

Joined: May 23, 2013
Posts: 1
You can do it like this


SQLQuery q=getSessionFactory().getCurrentSession().createSQLQuery(query);
q.addScalar("fechaalbaran", TimestampType.INSTANCE);
q.addScalar("sualbaran", StringType.INSTANCE);
q.addScalar("dtocomercial", DoubleType.INSTANCE);
q.addScalar("totdtocomercial", DoubleType.INSTANCE);
q.addScalar("dtopp", DoubleType.INSTANCE);
q.addScalar("totdtopp", DoubleType.INSTANCE);
q.addScalar("totalbruto", DoubleType.INSTANCE);
q.addScalar("totalimpuestos", DoubleType.INSTANCE);
q.addScalar("totalneto", DoubleType.INSTANCE);
q.addScalar("CODPROVEEDOR", IntegerType.INSTANCE);
q.addScalar("NOMPROVEEDOR", StringType.INSTANCE);
q.addScalar("alias", StringType.INSTANCE);
q.addScalar("orden", StringType.INSTANCE);
q.addScalar("CODALMACEN", StringType.INSTANCE);
q.addScalar("nombrealmacen", StringType.INSTANCE);
q.addScalar("INDICADOR_RETEFUENTE", StringType.INSTANCE);
q.addScalar("INDICADOR_RETEIVA", StringType.INSTANCE);
q.addScalar("INDICADOR_ICA", StringType.INSTANCE);
q.addScalar("codbanco", StringType.INSTANCE);
q.addScalar("descripcion", StringType.INSTANCE);
List list = q.setParameter("desde", desde).setParameter("hasta", hasta).list();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
 
Similar Threads
No Dialect mapping for JDBC type: -9
No Dialect mapping for JDBC type: -1
hibernate- Dialect mapping for JDBC
No Dialect mapping for JDBC type: -1
Problem with Hibernate Mapping