org.hibernate.hql.internal.ast.Q…

来源:互联网 发布:软件架构 豆瓣 编辑:程序博客网 时间:2024/05/17 06:45
Exception in thread "main"org.hibernate.hql.internal.ast.QuerySyntaxException:StudentEntity2 is not mapped [fromStudentEntity2]
atorg.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.
atorg.hibernate.QueryException.wrapWithQueryString(QueryException.
atorg.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.
atorg.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.
atorg.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.
atorg.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.
atorg.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.
atorg.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.
atorg.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.
atorg.hibernate.internal.SessionImpl.createQuery(SessionImpl.
atMainClass.main(MainClass.

  当出现这个类型错误的时候,肯定是“名字没对上”的问题。由于一个非常不小心的“图方便”,在try语句后的catch里面直接填了最顶级的Exception类,导致任何错误都直接抓取,不进行警告,debug半天看不出问题在哪儿。显示的现象就是啥都不显示,这是非常错误的。我们来看一看目录的结构:

org.hibernate.hql.internal.ast.QuerySyntaxException: <wbr> <wbr>is <wbr>not <wbr>mapped

关键部分的代码如下:
String sql ="from student_tbl";
Query que =session.createQuery(sql);
List<StudentEntity>msgs = que.list();
msgs.forEach((s)->{
   s.println();
});

  正是因为Hibernate已经把SQL映射成了面向对象的形式,所以即使真正存在于MySQL数据库里面的表名叫student_tbl,也不能直接“fromstudent_tbl”而要通过类名来select——即,这种形式:
org.hibernate.hql.internal.ast.QuerySyntaxException: <wbr> <wbr>is <wbr>not <wbr>mapped



0 0
原创粉丝点击