我在代码中的查询是
ArrayList lst = genericDao.query("select * from fdfiles where fileid = " + fileId);
在这一行,我得到了例外
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
我如何克服上述异常。
我的hibernate有属性
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
日志文件显示
java.lang.Exception: No Dialect mapping for JDBC type: -4; nested exception is org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
at com.duncansolutions.databus.dao.GenericDao.query(GenericDao.java:135)
at com.duncansolutions.databus.service.mechanismmanagement.datakey.FileListByLocationDaoService.getFile(FileListByLocationDaoService.java:151)
at com.duncansolutions.databus.html.DatakeyFileDownloadController.getFilebyId(DatakeyFileDownloadController.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:174)
答案 0 :(得分:0)
这种没有方言的JDBC类型映射:-4 异常似乎在hibernate尝试转换结果列表实际列表时,hibernate
无法识别列dataTypes
。
尝试使用HSQL
来获取如下记录。
假设您的fdfiles
已映射到FdFiles
实体
Query query = session.createQuery("SELECT fd.propert1,fd.property2 FROM FdFiles fd WHERE fd.fileId = :fileId");
query.setParameter("fileId", fileId);
List<FdFiles> list = query.list();