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

报错信息:

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对象)

  

猜你喜欢

转载自www.cnblogs.com/Jervisking/p/8903943.html