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 ...
随机推荐
- 验证性控件的使用--验证两个文本框至少有一个不为空CustomValidator
转:http://blog.163.com/zhaowencong_2010/blog/static/20402815220122103155643/ 有时候我们在注册一个帐号时要求我们留下电话号码, ...
- EF CodeFirst系列(5)---FluentApi
FluentApi总结 1.FluentApi简介 EF中的FluentApi作用是通过配置领域类来覆盖默认的约定.在EF中,我们通过DbModelBuilder类来使用FluentApi,它的功能比 ...
- JAVA传递带有空格的参数
String s="b2 + b1"; Process child = Runtime.getRuntime().exec("C:\\eclipse-workspace\ ...
- [物理学与PDEs]第2章习题7 一维不可压理想流体的求解
设有以 $x$ 轴为轴向的等轴截面管道, 其中充满着沿 $x$ 方向流动的不可压缩的理想流体, 在每一横截面上流体的状态相同, 且 $p=p(x)$. 若已知 $p(0) =p_1$, $p(L)=p ...
- [物理学与PDEs]第1章习题6 无限长载流直线的磁场
试计算电流强度为 $I$ 的无限长的直导线所产生的磁场的磁感强度. 解答: 设 $P$ 到直线的距离为 $r$, 垂足为 $P_0$, 则 ${\bf B}(P)$ 的方向为 ${\bf I}\tim ...
- 迅为iTOP-4418开发板-Android5.1系统编译补充
基于iTOP-4418开发板-Android5.1系统编译补充 5.6 编译-20181225 日期之后的源码 本文档补充介绍 4418 编译网盘目录 “J:\局域网共享_阮\iTOP4418 开发板 ...
- 新手如何理解JS面向对象开发?
今天有时间讲讲我对面向对象的理解跟看法,尽量用通俗的语言来表达,多多指教! 如今前端开发已经越来越火了,对于前端开发的要求也是越来越高了,在面试中,经常有面试官会问:你对JS面向对象熟悉吗? 其实,也 ...
- 第二周 数据分析之展示 Matplotlib基础绘图函数实例
Pyplot基础图表函数 Pyplot饼图的绘制: Pyplot直方图的绘制: Pyplot极坐标图的绘制: Pyplot散点图的绘制: 单元小结: import numpy as np import ...
- RabbitMQ 消息队列 二
一:查看MQ的用户角色 rabbitmqctl list_users 二:添加新的角色,并授予权限 rabbitmqctl add_user xiaoyao 123456 rabbitmqctl se ...
- WPF 杂记
1,跨屏最大化 单屏幕的时候我们可以设置 WindowState 来使应用最大化 当接多个屏幕的时候,就需要下面这个设置: private void FullScreen() { this.Windo ...