org.hibernate.exception.SQLGrammarException: could not extract ResultSet &&&&&Incorrect syntax near '@P0'.
这个故障的原因比较多:
1.如数据库中的字段和类中的字段类型不一致;
2.数据库dialect不够具体
myeclispe自动生成的是 org.hibernate.dialect.SQLServerDialect
如果连接的是SQLSERVER 2008 则可以写成org.hibernate.dialect.SQLServer2008Dialect
最近遇到这个报错:

现象就是 hql 的分页查询语句转换出错
select TOP ? employee0_.id as id1_2_, employee0_.EmpNr as EmpNr2_2_, employee0_.EmpChName as EmpChNam3_2_, employee0_.EmpName as EmpName4_2_, employee0_.Section as Section5_2_, employee0_.Shift as Shift6_2_, employee0_.OnDuty as OnDuty7_2_, employee0_.Title as Title8_2_ from database.dbo.employee employee0_ order by employee0_.id
应该?格式是(?),对应的错误提示是:Incorrect syntax near '@P0'.,
对应的是hql的分页查询语句query.setMaxResults(5);query.setFirstResult(0);由于这是自动生成的,所以不应该出错。
所以排查了很久,就想着看看hibernate.xml文件配置,发现Dialect之前动过了。
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
应该改成
<property name="dialect">
org.hibernate.dialect.SQLServer2008Dialect
</property>
这样转换的时候,sql语句会变成下图所示:
from Employee emp order by emp.id
Hibernate: select TOP(?) employee0_.id as id1_2_, employee0_.EmpNr as EmpNr2_2_, employee0_.EmpChName as EmpChNam3_2_, employee0_.EmpName as EmpName4_2_, employee0_.Section as Section5_2_, employee0_.Shift as Shift6_2_, employee0_.OnDuty as OnDuty7_2_, employee0_.Title as Title8_2_ from database.dbo.employee employee0_ order by employee0_.id
org.hibernate.exception.SQLGrammarException: could not extract ResultSet &&&&&Incorrect syntax near '@P0'.的更多相关文章
- 报错org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...
- Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...
- hibernate.exception.GenericJDBCException: could not extract ResultSet 解决办法
这句话翻译过来就是无法提取ResultSet 我在联查表的视图的时候发现的问题,明明之前好好的 那么你就得想想了 你再把错误信息往上翻翻,能不能看到 no viable alternative a ...
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
原因: 这个问题的解决方案很简单,主要是因为数据库中不存在相关的表或者列. org.springframework.dao.InvalidDataAccessApiUsageException: Pa ...
- org.hibernate.exception.SQLGrammarException: could not execute query
SSH项目中出现了 org.hibernate.exception.SQLGrammarException: could not execute query 错误,仔细检查后发现,是把createQu ...
- Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()
数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot eval ...
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
今天遇到了一个很坑人的问题,从昨晚一直搞到今天早上,终于发现了,先整理下: [背景]:利用hibernate自动给mysql创建一个表,然后为表里面添加一行记录,非常的简单(当然其中还涉及到sprin ...
- Hibernate: org.hibernate.exception.SQLGrammarException: could not insert: 错误
最近在学习Java Web,今天刚接触Hibernate.学习的书籍是<轻量级Java EE企业应用实战(第3版)>.书中367页5.2.2中给予的Hibernate例子中的代码运行有以下 ...
- Hibernate错误:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
报错:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execu ...
随机推荐
- Android应用程序国际化
前情提要 在Android应用程序中, 可以轻松更改语言, 以适应国际化标准 一些用户拥有多种语言习惯, 因此, 应用程序不能依赖设备默认语言环境, 必须提供更改显示语言的程序功能 本文章探寻持久化语 ...
- SQL Server 数据库编程技巧
Ø 简介 本文主要介绍 SQL Server 数据库在平常的开发中,可能会涉及到的编程技巧,主要包含以下内容: 1. 解决 SQL Server 不支持 127.0.0.1 登录 2. 查询 ...
- [译]Ocelot - Routing
原文 Ocelot主要的功能就是将http请求转发到对应的下游服务上去. Ocelot将一个请求路由到另外一个路由的动作叫做ReRoute.为了能让Ocelot能正常工作,需要在配置中设置ReRout ...
- windows7 java环境配置
最近在工作碰到了在ie浏览器调用java程序时,出现了一些问题,所以在这里整理一下: jdk的下载地址为:http://666dx.pc6.com/wwb3/jdkx6417.zip 正对于windo ...
- VIM --使用进阶 -- 插件篇 -- YouCompleteMe -- nerdtree
系统:ubuntu: 资源:https://github.com/ 其他:想了解都要哪些好用的插件,推荐大家读 http://blog.csdn.net/mergerly/article/detail ...
- phpcms V9首页、列表页以及内容页调用标签
1.页面标题:{$title} 2.发表时间:{$inputtime} 3.内容来源:{$copyfrom} 4.文章内容:{$content} 5.缩略图地址:{$thumb} 6.组图列表: {l ...
- 网络学习day02_OSI七层模型及数据的传输过程
title: 2018.9.2 OSI七层模型及数据的传输过程 tags: 计算机网络, OSI七层模型, 数据传输, 数据解封装 --- OSI七层模型和TCP/IP五层模型 OSI七层模型 我们说 ...
- Houdini SDF/Raymarching/等高曲面绘制
1 , SDF <1> union min(a,b) <2> intersect: max(a,b) <3> Substract a-b : if(b> ...
- ospf的虚连接配置
作者:邓聪聪 配置OSPF虚连接 组网需求 在图1中,Area2没有与骨干区域直接相连.Area1被用作传输区域(Transit Area)来连接Area2和Area0.SwitchA.SwitchB ...
- 题解P3711:【仓鼠的数学题】
这题黑的丫!怎么会掉紫呢! noteskey 伯努利数... 这里 有介绍哟~ 写的非常详细呢~ 反正这题就是推柿子... 另外就是黈力算法的运用 QWQ 我们令 \(ANS(x)\) 为答案多项式, ...