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 ...
随机推荐
- Nginx常用的平滑重启
之前在做运维工作中,经常需要添加虚拟主机,或者添加修改配置文件,但是测试环境还好,随便玩,如果是生产环境的话,既要保证配置不出问题,有不能中断服务.如果是这样的话,就需要对配置文件进行语法检测以及平滑 ...
- MapReduce-FileInputFormat
在运行 MapReduce 程序时,输入的文件格式包括:基于行的日志文件.二进制格式文件.数据库表等.那么,针对不同的数据类型,MapReduce 是如何读取这些数据? FileInputFormat ...
- Groovy 设计模式 -- 享元模式
Flyweight Pattern 享元模式, 将对象的相同属性, 以节省内存为目的,存储为一份公共对象, 所有对象共用此分对象. The Flyweight Pattern is a pattern ...
- 6.linux安装tomcat
1.下载安装包 https://tomcat.apache.org/download-80.cgi 2.用 WinSCP 将本地的安装包 上传到 linux 服务器中 3.解压安装包( ...
- [好文mark] 深度学习中的注意力机制
https://cloud.tencent.com/developer/article/1143127
- 使用putty连接Ubuntu虚拟机,使用ssh方式访问
1 前言 Ubuntu14.04版本是可以直接连接的,没想到新装的Ubuntu18.04竟然没有默认安装ssh. 则安装一下open-ssh-server就可以的. 2 步骤 2.1 更新一下源 命令 ...
- VMware Workstation 15 Pro 永久激活密钥 下载
注:本文来源于:Felix__H 的<VMware Workstation 15 Pro 永久激活密钥 下载 > 一. 激活密钥 YG5H2-ANZ0H-M8ERY-TXZZZ-YKRV8 ...
- linux在telnet情况下root登录提示login incorrect
root登录时总是提示 login incorrect SSH可以登录 别的用户也可以通过telnet登录 唯独root不可以 解决方法: vi /etc/pam.d/login # auth r ...
- Object.freeze(); 方法冻结一个对象。
Object.freeze() 方法可以冻结一个对象.一个被冻结的对象再也不能被修改: 冻结了一个对象则不能向这个对象添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性.可配置性.可写性 ...
- Django-ORM多表操作(进阶)
一.创建模型 下面我们通过图书管理系统,来设计出每张表之间的对应关系. 通过上图关系,来定义一下我们的模型类. from django.db import models class Book(mode ...