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

Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: StudentEntity2 is not mapped [from StudentEntity2]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.
at org.hibernate.QueryException.wrapWithQueryString(QueryException.
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.
at MainClass.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,也不能直接“from student_tbl”而要通过类名来select——即,这种形式:
org.hibernate.hql.internal.ast.QuerySyntaxException: <wbr> <wbr>is <wbr>not <wbr>mapped



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值