Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
org.hibernate.hql.ast.QuerySyntaxException:未映射表名_Hibernate - Fatal编程技术网

org.hibernate.hql.ast.QuerySyntaxException:未映射表名

org.hibernate.hql.ast.QuerySyntaxException:未映射表名,hibernate,Hibernate,我面临异常:org.hibernate.hql.ast.QuerySyntaxException:Student6未映射[来自Student6 stud] 在sql server数据库中,我的表名是Student6,pojo类名是Student public static void main(String[] args) { Configuration configuration = new Configuration(); SessionFactory session

我面临异常:org.hibernate.hql.ast.QuerySyntaxException:Student6未映射[来自Student6 stud] 在sql server数据库中,我的表名是Student6,pojo类名是Student

    public static void main(String[] args) {
    Configuration configuration = new Configuration();
    SessionFactory  sessionFactory = configuration.configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    try {
        String SQL_QUERY ="from Student6 stud";
             Query query = session.createQuery(SQL_QUERY);
             for(Iterator it=query.iterate();it.hasNext();)             {
             Object[] row = (Object[]) it.next();
             System.out.println("STUDENT_ID: " + row[0]);
             System.out.println("STUDENT_NAME: " + row[1]);
             System.out.println("ADDRESS_STREET: " + row[2]);
             System.out.println("ADDRESS_CITY: " + row[3]);
             System.out.println("ADDRESS_STATE: " + row[4]);
             System.out.println("ADDRESS_ZIPCODE: " + row[5]);                               }

    } catch (HibernateException e) {
        transaction.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
}

您的查询不是SQL查询。这是一个HQL查询。因此,它不应该使用表名,而应该使用实体类名(
来自Student
,而不是
来自Student6
)。它不会以
Object[]
实例的形式返回行,而是返回实体实例


Hibernate是一个ORM:一个对象关系映射器。其思想是使用对象而不是关系数据。你应该重新阅读。

@JB Nizet-谢谢你的好答案我反应太快了,我没有注意到“学生”和“学生6”之间的区别:)谢谢,我搜索了一下,这就是答案。