org.hibernate.hql.internal.ast.QuerySyntaxException
程序员文章站
2022-04-13 08:40:08
...
笔者在做一个SSH项目时遇到以下的问题,已解决,特此记录。
对应表格Users的实体类是User(在Postgres中应该是不允许创建User表的,因为User是关键字)。
当我的hql语句是
String hsql = "from Users u where u.id='" + id + "'";
出现以下error
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Users is not mapped [from Users u where u.id='1']
后来了解了以下hql语句和sql语句的区别。
hql语句是面向对象的,而sql语句是面向表格的,简单来说在hql中from跟的是对象名而不是表名。
所以将上述hql语句改为
String hsql = "from User u where u.id='" + id + "'";
再次运行,通过。
推荐阅读
-
org.hibernate.hql.internal.ast.QuerySyntaxException: agency is not mapped
-
org.hibernate.hql.internal.ast.QuerySyntaxException: agency is not mapped
-
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
-
JSP:org.hibernate.hql.internal.ast.QuerySyntaxException: catalog is not mapped [from catalog]
-
org.hibernate.hql.internal.ast.QuerySyntaxException: stu1 is not mapped [from stu1]
-
hibernate执行报错org.hibernate.hql.internal.ast.QuerySyntaxException: XXX is not mapped
-
org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped报错解决
-
org.hibernate.hql.internal.ast.QuerySyntaxException 异常处理
-
org.hibernate.hql.internal.ast.QuerySyntaxException