码迷,mamicode.com
首页 > 移动开发 > 详细

SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]

时间:2018-04-21 22:25:33      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:报错信息   sql   query   hql   问题   list   tab   ...   mysq   

报错信息:

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 where username = ?]

标签:报错信息   sql   query   hql   问题   list   tab   ...   mysq   

原文地址:https://www.cnblogs.com/Jervisking/p/8903943.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!