<%
    org.hibernate.Session s = HibernateSessionFactory.currentSession();
    String hql = "from Xmb where dl=:dl order by xh asc";
    Lbb dl = (Lbb)s.get(Lbb.class, new Integer(1));
    List list = s.createQuery(hql).setEntity("dl", dl).list();
    Xmb xmb = null;
    for (Iterator its = list.iterator(); its.hasNext(); ) {
        xmb = (Xmb)(Object)its.next();
。。(读数据)
    }
    HibernateSessionFactory.closeSession();
    xmb = null;
    list = null;
    hql = null;
%>
报错:
org.hibernate.exception.SQLGrammarException: could not execute query
=========================Lbb dl = (Lbb)s.get(Lbb.class, new Integer(1));是没有问题的,试验过,成功得到持久化类
不知出了什么问题?

解决方案 »

  1.   

    是List list = s.createQuery(hql).setEntity("dl", dl).list();的list()这里报错
      

  2.   

    http://community.csdn.net/Expert/topic/4970/4970357.xml?temp=5.991763E-02
      

  3.   

    把hibernate配置文件中的show_sql开关打开,看控制台打印的sql语句是什么
    ——不好意思,怎么看控制台?服务在后台,没有开控制台窗口呀?
      

  4.   

    知道怎么做了。
    控制台输出的SQL语句信息如下:
    Hibernate: select xmb0_.xh as xh3_, xmb0_.xmm as xmm3_, xmb0_.lbh as lbh3_, xmb0_.dlh as dlh3_, xmb0_.lx as lx3_, xmb0_.yxhj as yxhj3_, xmb0_.yy as yy3_, xmb0_.dx as dx3_, xmb0_.pj as pj3_, xmb0_.djsj as djsj3_, xmb0_.xgsj as xgsj3_, xmb0_.author as author3_, xmb0_.authorurl as authorurl3_, xmb0_.tp as tp3_, xmb0_.passwd as passwd3_, xmb0_.jj as jj3_, xmb0_.lr as lr3_, xmb0_.tj as tj3_, xmb0_.sc as sc3_ from softdown.xmb xmb0_ where dl=? order by xmb0_.xh asc
    看上去没什么不对的呀?
      

  5.   

    解决了。取了别名就正常了:from Xmb x where x.dl = :dl order by x.xh asc