No Dialect mapping for JDBC type 错误分析
当在hibernate中运用原始的sql语句进行操作的的时候,常常会报错,错误很多都是关于
No Dialect mapping for JDBC type类型的错误,经过分析和查找,问题常常发生在几个地方
1、错误的配置了hibernate的方言
2、就是你的数据库中的字段和java里面的类型不匹配的问题
具体信息如:
eg:
Session session = HibernateSessionFactory.getSession();
String sql = "SELECT Daymarketinfo.* FROM (select * from daymarketinfo d order by market_time desc ) as Daymarketinfo group by contract_id;";
Query query = session.createSQLQuery(sql);
List<?> list = query.list();//错误出现位置
List<JsonData> jsonList = new ArrayList<JsonData>();
for (Object obj : list) {
Object[] arr = (Object[])obj;
JsonData oJson = new JsonData();
oJson.setId((Integer)arr[0]);
/*
对arr数组取出一个个取出相应的数据就可以了,在这里就不多赘述
*/
jsonList.add(dk);
}
request.setAttribute("jsonList", jsonList);
return mapping.findForward("success");
错误信息如下:
org.hibernate.MappingException: No Dialect mapping for JDBC type: 7
at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:192)
at org.hibernate.loader.custom.CustomLoader.getHibernateType(CustomLoader.java:161)
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:131)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1678)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
at com.futures.action.manage.DaymarketinfoAction.execute(DaymarketinfoAction.java:57)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:105)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proces