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.
关键部分的代码如下:
String sql = "from student_tbl";
Query que = session.createQuery(sql);
List<StudentEntity> msgs = que.list();
msgs.forEach((s)->{
});
正是因为Hibernate已经把SQL映射成了面向对象的形式,所以即使真正存在于MySQL数据库里面的表名叫student_tbl,也不能直接“from student_tbl”而要通过类名来select——即,这种形式: