http://www.chinaitlab.com/www/news/article_show.asp?id=31348

解决方案 »

  1.   

    这个可以回答你
    http://community.csdn.net/Expert/TopicView3.asp?id=4165158
      

  2.   

    public List getStudents(int position, int length) throws Exception{
    String hql=" select student from Student as student order by student.id desc ";
    Query query =getSession().getNamedQuery(hql);
    query.setFirstResult(position);
    query.setMaxResults(length);
    return query.list(); 
    }
    为什么在运行这个方法时,出错:
    org.hibernate.MappingException: Named query not known:  select student from Student as student order by student.id desc 
      

  3.   

    这样肯定不行了,Named query是一种让你把hql从代码中分离出来(到hbm.xml中)的机制,比如:
    //xx.hbm.xml
    <query name="aQuery"><![CDATA[
                from User u order by u.userID asc
            ]]></query>
    </hibernate-mapping>//java code
    getSession().getNamedQuery(aQuery);
    我一两句话说不清出,你自己研究一下它怎么用吧