String hql="   from DEPT where deptno='94' ";  有问题
DEPT是你的类名,不是表名

解决方案 »

  1.   

    是这个表啊 
    select Dname from DEPT where deptno='94';
    这句在cmd里都可以正确执行,而且我就是用的scott下那四个表
      

  2.   

    问题在这,看这句错误提示
    Hibernate: select  from where (deptno='94'  )根本没有选择对象,是不是还要set什么东西进去
      

  3.   

    net.sf.hibernate.exception.SQLGrammarException: Could not execute query
    Hibernate: select  from where (deptno='94' )
    应该是类中缺少set函数。
      

  4.   

    哦,那我怎么办?看例子代码中并没有做什么set啊
      

  5.   

    import net.sf.hibernate.SessionFactory;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.cfg.Configuration;
    import net.sf.hibernate.HibernateException;
    import net.sf.hibernate.Transaction;
    import net.sf.hibernate.Query;
    import java.util.Iterator;
    import net.sf.hibernate.collection.List;
    import net.sf.hibernate.collection.Set; public class Test{
        public Test() {
            try {
                jbInit();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }    public static void main(String[] args) {try{
        String hql="   from DEPT ";
           Configuration config=new Configuration().configure();
             SessionFactory sf =config.buildSessionFactory();
             Session session =sf.openSession();
         
      List list=(List)session.createQuery(hql);
       Iterator it=list.iterator();
        
       while (it.hasNext())
            {
           Dept dept=(Dept)it.next();
            System.out.println(it.next());
            }
      }    catch (HibernateException e) {
        e.printStackTrace();
        }     }    private void jbInit() throws Exception {
        }
    }错误如下:
    Hit uncaught exception java.lang.ClassCastException
      

  6.   

    1.从"Dept dept=(Dept)it.next();"可以看出你的类应该是"Dept",所以query 语句应该是 String hql="   from Dept where deptno='94' ";
    2 要保证你的Dept类里有setDeptno method.
      

  7.   

    1和2都满足了,已经String hql="   from DEPT where deptno='94' ";
    了,
    确有setDeptno method.错误如下
    Hibernate: select  from where (deptno='94' )
      

  8.   

    是String hql="   from Dept where deptno='94' ";
      

  9.   

    hibernate不是很懂,看你的问题出在SQL的写法上,最好的办法用数据库的服务器跟踪一下,看执行的SQL是什么样的,就能判断出少‘,还是什么问题!希望对你有帮助!
      

  10.   

    数据库的服务器跟踪一下,应该是把你的hql打印出来看看.
      

  11.   

    Hibernate: select  from where (deptno='94' )