SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user wher

Posted jervisking

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user wher相关的知识,希望对你有一定的参考价值。

报错信息:

ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from user where username = ?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
org.springframework.orm.hibernate3.HibernateQueryException: user is not mapped [from user where username = ?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
......
Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
......

看到信息的第一反应,映射出错

  1.有无User.hbm.xml文件

  2.该配置文件是否加载到hibernate实体列表中

  3.映射文件字段是否与数据库字段一致,有无误用关键字

--> 依旧错误(既然不是User的错,那就是数据库问题)

  为图方便一开始数据库方言是mysqlDialect,兼容性可能出现问题,改为Mysql5Dialet ,即配置<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>

-->依旧错误(**数据库语句错误?**

  String hql = "from user where username = ?";
  List<User> list = this.getHibernateTemplate().find(hql, username);  错误???

  重点:hql采用实体查询技术,比如下面的例子:String hql=”from User user ”; List list=session.CreateQuery(hql).list(); 上面的代码执行结果是,查询出User实体对象所对应的所有数据,而且将数据封装成User实体对象,并且放入List中返回

所以,上面的hql语句错误,hql语句,一定是对象查询,特别是【tableName】 不要写你要查询的表,而是查询的对象

(此处,user是数据库表名,应该查询的是User对象)

  

 






以上是关于SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user wher的主要内容,如果未能解决你的问题,请参考以下文章

SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start Em

报错org.apache.catalina.LifecycleException caused by java.lang.NoSuchMethodError: javax.servlet.Servle

启动HBase2.1.0报错Caused by: java.lang.ClassNotFoundException: org.apache.htrace.SamplerBuilder

SpringBoot 报错Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘*****‘

SpringBoot 报错Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘*****‘

CloudSim4.0报错NoClassDefFoundError,Caused by: java.lang.ClassNotFoundException: org.apache.commons.ma