我的函数如下:   
  public   List   getSorts()   throws   HibernateException   {   
  Session   session   =   HibernateUtil.currentSession();   
  Transaction   tx   =   session.beginTransaction();   
  List   list=null;   
  try   {   
  Query   query   =   session.createQuery("from   Sort");   //鍒涘缓鏌ヨ瀵硅薄   
  list   =   query.list();     
  tx.commit();   
  }   catch   (HibernateException   e)   {   
  if   (tx   !=   null)   
  tx.rollback();   
  throw   e;   
  }   
  HibernateUtil.closeSession();   
  return   list;     
  }   
    
  我在调用的时候出现这样的问题:   
  org.hibernate.exception.SQLGrammarException:   could   not   execute   query   
    
  请教高手怎么回事,分不多,请帮帮小弟了!谢谢!! 

解决方案 »

  1.   

    1、检查你有没有Sort.java类
    2、检查你的Sort.java有没有在hibernate.cfg.xml文件里面进行映射
    另外,查询是不需要commit提交事务的。
      

  2.   

    不是表被锁了就是Sort对应的映射不存在
    检查你HIBERNATE配置文件Sort对应关系
      

  3.   


    可能是映射的不对吧..不知道你用的hibernate的版本是多少..在Sort后面加个别名as s试下.
      

  4.   

    对 首先查看 Sort是否存在 其次查看 配置文件是否写的正确 并且是否添加到了hibernate.cfg.xml