Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User user where user.name=?0 and user.pass=?1]

at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)

at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)

at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)

at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:322)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3441)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:584)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)

at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)

at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)

at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)

at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)

at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)

at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)

at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)

at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)

at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)

at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)

at com.login.hibernate.HqlQuery.findUser(HqlQuery.java:17)

at com.login.hibernate.HqlQuery.main(HqlQuery.java:27)

其实错误提示说得很清楚了,就是没有添加映射,只要在src下的hibernate.cfg.xml中增加相应类的映射即可。

时间: 2024-10-05 11:36:16

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [from User的相关文章

org.hibernate.hql.ast.QuerySyntaxException

org.hibernate.hql.ast.QuerySyntaxException: eg:org.hibernate.hql.ast.QuerySyntaxException: Admin is not mapped [select count(a)from Admin a where a.adminname=? and a.adminpwd=?] 问题原因 1.      from 后面跟着的是实体类名,而不是表名 2.      Hql语句写错. 3.      没有添加映射文件或者没有

Hibernate 5.X 版本中Exception in thread &quot;main&quot; org.hibernate.MappingException: Unknown entity: cn.xxx.p

最近开始使用最新版本的Hibernate5,所有的配置感觉都正确却还是没有结果. 使用如下: public static void main(String[] args) throws Exception { Configuration cfg = new Configuration().configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.get

ERROR: Field &#39;PostId&#39; doesn&#39;t have a default value Exception in thread &quot;main&quot; org.hibernate.exception.GenericJDBCException: could not execute statement

例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的错误. INFO: HHH000232: Schema update complete Hibernate: insert into Post (postName) values (?) 八月 19, 2018 5:07:17 下午 org.hibernate.engine.jdbc.spi.SqlExcep

org.hibernate.hql.ast.QuerySyntaxException: User i

错误分析: 本来是想将User类映射的表名命名为t_user,由于粗心,写成@Entity(name="t_user"). @Entity(name="t_user")的意思是为这个实体类的名字,这样得到的实体类和表的映射关系为  实体类t_user-->表t_user,因此from User找不到相应的映射关系 解决方法: @Entity @Table(name="t_user")   //指定映射的表名 public class Use

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: table is not Mapped问题解决

引言: 在基于SpringData/JPA来快速开发若干功能过程中,碰到了table is not Mapped问题,经过一番辛苦的调试测试之后,才发现了一个@Entity的属性name的妙用. 1. 问题的提出 场景描述: 在开发中,做几个功能类似的模块,但代码需要独立,方便后续的独立部署.故出现了很多包路径不同,但是类的名称类似的类.在Model中定义了很多名称相同的实体类,都是以@Entity来定义的. @Entity @Table(name="table1") public c

weblogic 下异常 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

项目之前在 Tomcat 环境下一直都正常运行,今天应客户要求需要迁移到 webLogic 10.3.6 下, 部署后竟然抛出了 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken 异常,经过一番搜索后弄明白了问题的产生原因及解决方法. 问题原因 Hibernate3 采用新的基于 antlr 的 HQL/SQL 查询翻译器,在 hibernate3 中需要用到 antlr,然而

Hbase delete遇到的常见异常: Exception in thread &quot;main&quot; java.lang.UnsupportedOperationException

hbase 执行批量删除时出现错误: Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:161) at org.apache.hadoop.hbase.client.HTable.delete(HTable.java:852) 这种异常其实很常见,remove操作不支持,为什么会出现不支持的情况呢?检查

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V

TestNG运行时报以下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.testng.TestNG.configure(Lorg/testng/CommandLineArgs;)V at org.testng.remote.AbstractRemoteTestNG.configure(AbstractRemoteTestNG.java:77) at org.testng.remote.RemoteTestN

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

MyEclipse运行的时候报错,菜鸟不理解是什么意思,最后找了一些资料才知道是因为缺少commons-logging.jar包 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66) at c