日期:2014-05-16  浏览次数:20394 次

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

?Java代码:

?

public List<Object[]> getPlateNumberAndDate(){   
	    return getHibernateTemplate().executeFind(new HibernateCallback(){   
	        public Object doInHibernate(Session session)   
	                throws HibernateException, SQLException {   
	            Query q = session.createSQLQuery("SELECT top 5 VEHICLE_NUM, ALARM_DATE FROM [dbo].[ALARM_PROCESS] WHERE CHULI_TAG IS NULL");
	            return q.list();   
	        }              
	    });   
	}

?

异常:

?

Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: No Dialect mapping for JDBC type: -16; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -16
	at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
	at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
	at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
	at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:343)
	at alpha.gpsf.dao.impl.SpeedingQueryDAOImpl.getPlateNumberAndDate(SpeedingQueryDAOImpl.java:43)
	at alpha.gpsf.dao.impl.SpeedingQueryDAOImpl.main(SpeedingQueryDAOImpl.java:106)
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -16
	at org.hibernate.dialect.TypeNames.get(TypeNames.java:79)
	at org.hibernate.dialect.TypeNames.get(TypeNames.java:104)
	at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:393)
	at org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:582)
	at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:508)
	at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:524)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:1817)
	at org.hibernate.loader.Loader.doQuery(Loader.java:697)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
	at org.hibernate.loader.Loader.doList(Loader.java:2228)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
	at org.hibernate.loader.Loader.list(Loader.java:2120)
	at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)
	at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1722)
	at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
	at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
	at alpha.gpsf.dao.impl.SpeedingQueryDAOImpl$2.doInHibernate(SpeedingQueryDAOImpl.java:48)
	at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
	... 3 more

?

关键异常:

?

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

?

原因:hibernate中native sql对于数据库的某些数据类型不支持,数据类型不能成功映射。

?

解决办法:

?

在取数据的时候用下CONVERT函数,把类型转成varchar就行了,测试得知varchar类型没问题

?

Query q = session.createSQLQuery("SELECT top 5 CONVERT(varchar(25),VEHICLE_NUM), CONVERT(varchar(25),ALARM_DATE,20) FROM [dbo].[ALARM_PROCESS] WHERE CHULI_TAG IS NULL");

?

?