非常诡异的报错,信息如下:
org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select count(*) from User u where u.userName=? and u.userPassword=? ]
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
类似的报错信息的解决方法,我也是研究了半天才最后发现问题
出现这中错误情况有两种

1,配置文件没有加载到hibernate的实体列表里面

2,映射文件的字段与数据库字段不一致,或者名称不一致导致

hql 是 有专门的语法的。 不是sql。你把hibernate方言设置成你用的数据库。
sql的语法和hql不是一回事。
......QuerySyntaxException...是说,你要的sql不是hql,语法错误。。

1.看是否忘记将hibernate的映射文件添加到Hibernate.cfg.xml(使用Hibernate时)或者applicationContext.xml中

2.检查表中的字段和映射文件中的字段是否一一对应

3.检查字段名是否使用了数据库中的关键字

4.HQL语句是否正确

HQL: Hibernate 查询语言Hibernate 配备了一种非常强大的查询语言,这种语言看上去很像 SQL。但是不要被语法结构上的相似所迷惑,HQL 是非常有意识的被设计为完全面向对象的查询,它可以理解如继承、多态和关联之类的概念。

所以这个时候你要认真检查一下你写的hql语句,一定是对象查询,特别是【tableName】 不要写你要查询的表,而是查询的对象

比如:

public long getTypeCount(Patent patent) {
String hqlString = "select count(*) from Patent as p where p.type ='"+patent.getType()+"'";
Query query = this.getSession().createQuery(hqlString);
long count =0;
count = ((Number)query.uniqueResult()).intValue();
return count;
}

Patent  是一个对象

而数据库的表名是patent   如果写成String hqlString = "select count(*) from patent as p where p.type ='"+patent.getType()+"'";

肯定是查询不出结果的,切记!

如果这篇文章对您有帮助,请随便打赏一点点,作为鼓励,非常感谢您!!!!

SSH整合报错:org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped[......]的更多相关文章

  1. java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: student is not mapped

    Spring 5.0 +Jpa,使用@Query实现 自定义查询报错: java.lang.IllegalArgumentException: org.hibernate.hql.internal.a ...

  2. 继承映射中的java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: person is not mapped [FROM person]

    继承映射中查询对象的过程中报错: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxExcep ...

  3. org.hibernate.hql.internal.ast.QuerySyntaxException: XXX is not mapped

    异常情况: 最近在把一个项目拆分多个 module 的时候数据库查询遇到这个异常:org.hibernate.hql.internal.ast.QuerySyntaxException: Identi ...

  4. Spring Data JPA开发中遇到的问题1:org.hibernate.hql.internal.ast.QuerySyntaxException: DispatchShift is not mapped

    org.hibernate.hql.internal.ast.QuerySyntaxException: T_D_SHIFT_DISPATCH is not mapped 错误原因: 没有映射到表,经 ...

  5. org.hibernate.hql.internal.ast.QuerysyntaxException:user is not mapped [from User where user_code=? and user_password=?]

    初学者,一个很低级的错误吧! 找不到映射,最后发现没把类的Hibernate映射文件 添加到Hibernate核心配置文件中去,所以报了这个异常! 在核心文件中添加映射   <mapping r ...

  6. JPA使用中遇到Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: XXX is not mapped

    在写自定义查询时,Query注解中写的JPQL,表名和列名都应该是映射的Java类和属性,不能写表名或者字段名

  7. WebLogic使用SSH架构部署遇到org.hibernate.hql.internal.ast.HqlTok

    其实这个问题在以前就遇到过,当时解决了,但今天在部署一个测试轻应用的时候一直没有想起来,特此记录一下. 这个问题出现在使用WebLogic(我使用的是10.3.5版本)发布SSH架构的应用.在操作数据 ...

  8. ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决

    ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决 根据异常提示:我找了我的MySQL语句:果然 ...

  9. SSH整合报错:Unable to instantiate Action, testAction, defined for 'test' in namespace '/'testAction

    报错如下: Struts Problem Report Struts has detected an unhandled exception: Messages: testAction Unable ...

随机推荐

  1. [NOIP2014]联合权值 题解

    题目大意: 有一棵树,求距离为2的点权的乘积的和以及最大值. 思路: 枚举每一个点,则与其相邻的点互为距离为2的点.该部分的最大值为点权最大的两个点的积,和为点的权值和的平方减去每个点的平方,这样每条 ...

  2. Excel大批量导入数据到SQLServer数据库-万条只用1秒

    private string ExcelToStudent() { /*---*/ var preStr = DateTime.Now.ToString("yyyyMMddHHmmssfff ...

  3. java分享第十三天(fastjson生成和解析json数据,序列化和反序列化数据)

     fastjson简介:Fastjson是一个Java语言编写的高性能功能完善的JSON库.fastjson采用独创的算法,将parse的速度提升到极致,超过所有json库,包括曾经号称最快的jack ...

  4. Python实战2( 接上):扫描多余中文

    还是接上一篇,扫描多余中文,支持自定义忽略字段 源代码,详看   http://pan.baidu.com/s/1ntC78Zv   ScanChinese.zip

  5. Volley

    Volley 是 Google 推出的轻量级 Android 异步网络请求框架和图片加载框架.在 Google I/O 2013 大会上发布.其适用场景是数据量小,通信频繁的网络操作. 主要特点: ( ...

  6. 安卓中級教程(6):annotation的基本用法

    package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...

  7. 简单的行为控制管理方法,自动登录,session定时验证码过期

    代码很简单 实现的方式很多,用cookies 用static 变量 file文件缓存 等等 比如 //简单行为管理,如果请求此方法次数多于5次,就显示验证码 吧当前方法的name传进来,有效时间是5分 ...

  8. python学习道路(day4note)(函数,形参实参位置参数匿名参数,匿名函数,高阶函数,镶嵌函数)

    1.函数 2种编程方法 关键词面向对象:华山派 --->> 类----->class面向过程:少林派 -->> 过程--->def 函数式编程:逍遥派 --> ...

  9. hadoop2.7下载mirror

    http://mirror.bit.edu.cn/apache/hadoop/common/

  10. IE 6 ~ 9 CSS Hack 写法总结

    IE 6 ~ 9 CSS Hack 写法总结 24th 四, 14 lip2up [code lang="css"]_color: red;    /* ie6 */*color: ...