org.hibernate.exception.SQLGrammarException: could not execute query

// 打开会话
Session session = HibernateUtil.getSession();
// 开启事务
Transaction tx = null;
Wine wine;
try {
tx = session.beginTransaction();

String sql = "SELECT * FROM wine WHERE W_ID >= (SELECT floor(RAND() * (SELECT MAX(W_ID) FROM wine))) ORDER BY W_ID LIMIT 1 ; ";
// 使用会话获得对象
SQLQuery query = session.createSQLQuery(sql);
query.addEntity(Humor.class);
wine = (Wine) query.list().get(0);
// 提交事务
tx.commit();

除去SQL语法错误,还有可能是设置错误的实体,这样大意的错误不能再犯

时间: 2024-10-06 10:49:03

org.hibernate.exception.SQLGrammarException: could not execute query的相关文章

org.hibernate.exception.SQLGrammarException: could not execute query 没有找到数据库

org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) org.hibernate.loader.Lo

org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update,码迷,mamicode.com org.hibernate.exception.SQLGrammarException: Could not execute JDBC batc

Java EE 之 Hibernate异常解决:org.hibernate.exception.SQLGrammarException: could not execute statement

本质原因:配置的Java Bean,由Hibernate自动产生的SQL语句中有语法错误 原因如下: 情况1.存在字段名/表名与数据库关键字冲突 情况2.MySQL5.0以后与MySQL5.0以前事务引擎InnoDB配置微妙不同 解决方案: //MySQL 5.0之后[engine = InnoDB] <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</proper

exception is org.hibernate.exception.DataException: Could not execute JDBC batch update at

没有什么问题,但是却报了Could not execute JDBC batch update的错,主要是配置文件设置了关联,数据却没有关联造成的,只要数据正确就没有问题. 另外,造成这个原因的还可能是数据库的驱动jar包不支持. 还有就是csdn的dizhang的专栏提到的下面问题引起的: 1.因为Hibernate Tools(或者Eclipse本身的Database Explorer)生成*.hbn.xml工具中包含有catalog="***"(*表示数据库名称)这样的属性,将该

Exception occurred during processing request: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

今天在编码的时候遇到了 Exception occurred during processing request: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet这个问题,也是找了老半天不懂什么原因,后来找了好多论坛,总结了一下,只要出现了sql的问题,基本都是bean或者XXX.

hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)

首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to-one关系 1 <?xml version="1.0"?> 2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 3 "http:/

HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement

1.什么操作出现:当我在项目中添加产品或者修改时,浏览器出现HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement; Ecplise出现这个: 十二月 20, 2017 1:51:02 下午 org.apache.catalina.core.StandardWrapperVal

ERROR: Field &#39;PostId&#39; doesn&#39;t have a default value Exception in thread &quot;main&quot; org.hibernate.exception.GenericJDBCException: could not execute statement

例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的错误. INFO: HHH000232: Schema update complete Hibernate: insert into Post (postName) values (?) 八月 19, 2018 5:07:17 下午 org.hibernate.engine.jdbc.spi.SqlExcep

Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.springframework.orm.jpa.vendor.HibernateJpaDi