Hibernate异常: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
2017-04-17 22:39
453 查看
Hibernate异常:org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
1、出现该错误的情况分析
1,配置文件没有加载到hibernate的实体列表里面2,映射文件的字段与数据库字段不一致,或者名称不一致导致
hql 是 有专门的语法的,不完全同于sql。切记HQL是大小写敏感的,这点不同于SQL。
……QuerySyntaxException…说的就是hql语法有问题,相信你在cmd中使用sql查询中就经常见到下面错误
You have an error in your SQL syntax;
1.看是否忘记将hibernate的映射文件添加到Hibernate.cfg.xml(使用Hibernate时)或者applicationContext.xml中
2.检查表中的字段和映射文件中的字段是否一一对应
3.检查字段名是否使用了数据库中的关键字
4.HQL语句是否正确
2、HQL对比SQL
HQL: Hibernate 查询语言Hibernate 配备了一种非常强大的查询语言,这种语言看上去很像 SQL。但是不要被语法结构上的相似所迷惑,HQL 是非常有意识的被设计为完全面向对象的查询,它可以理解如继承、多态和关联之类的概念。 通常错误就在from 后面的tableName,sql语句中我们当然放的是tableName,而且大小写可以随便写。但是HQL中,我们要在from 后面放对象(Object),比如我们建立了user表,User类。
错误查询
String hql ="from user"; Query query=session.createQuery(hql);
正确查询
String hql ="from User"; Query query=session.createQuery(hql);
相关文章推荐
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User] 异常总结
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User] 异常总结
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
- SSH出错--hibernate--org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User]
- SSH整合报错:org.hibernate.hql.ast.QuerySyntaxException: userinfo is not mapped [from userinfo]
- org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User].
- 异常:org.hibernate.hql.ast.QuerySyntaxException: EmpModel is not mapped [from EmpModel where name = ?
- org.hibernate.hql.internal.ast.QuerySyntaxException: Admin is not mapped [from Admin where username=
- org.hibernate.hql.internal.ast.QuerySyntaxException: userinfo is not mapped [from userinfo u where u
- SSH报错:org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [select o from User o where 1=1
- org.hibernate.hql.ast.QuerySyntaxException is not mapped异常
- org.hibernate.hql.ast.QuerySyntaxException: is not mapped 异常总结
- org.hibernate.hql.ast.QuerySyntaxException: Category is not mapped [from Category]
- org.hibernate.hql.ast.QuerySyntaxException: is not mapped 异常总结
- org.hibernate.hql.ast.QuerySyntaxException per is not mapped [from Per as p]
- org.hibernate.hql.ast.QuerySyntaxException is not mapped异常
- org.hibernate.hql.ast.QuerySyntaxException:is not mapped 异常总结
- org.hibernate.hql.ast.QuerySyntaxException: **** is not mapped 异常总结
- org.hibernate.hql.ast.QuerySyntaxException is not mapped异常
- 关于org.hibernate.hql.ast.QuerySyntaxException: 关键字命名的类 is not mapped [from 关键字命名的类 ]