2011-10-27 08:41:52,625 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - HQL: from ssh2.wq.fn.entity.Question q order by q.answernum desc
2011-10-27 08:41:52,625 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] - SQL: select question0_.QSID as QSID2_, question0_.USERSID as USERSID2_, question0_.TITLE as TITLE2_, question0_.CONTENT as CONTENT2_, question0_.STATU as STATU2_, question0_.ANSWERNUM as ANSWERNUM2_, question0_.TIME as TIME2_, question0_.usersid as usersid2_ from WQFN.QUESTION question0_ order by question0_.ANSWERNUM desc
2011-10-27 08:41:52,625 DEBUG [org.hibernate.hql.ast.ErrorCounter] - throwQueryException() : no errors
2011-10-27 08:41:52,625 DEBUG [org.hibernate.engine.query.HQLQueryPlan] - HQL param location recognition took 0 mills (from Question q order by q.answernum desc)
2011-10-27 08:41:52,625 DEBUG [org.hibernate.engine.query.QueryPlanCache] - located HQL query plan in cache (from Question q order by q.answernum desc)
2011-10-27 08:41:52,625 DEBUG [org.hibernate.engine.query.HQLQueryPlan] - find: from Question q order by q.answernum desc
2011-10-27 08:41:52,625 DEBUG [org.hibernate.engine.QueryParameters] - named parameters: {}
2011-10-27 08:41:52,625 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2011-10-27 08:41:52,625 DEBUG [org.hibernate.jdbc.ConnectionManager] - opening JDBC connection
2011-10-27 08:41:52,671 DEBUG [org.hibernate.SQL] - select * from ( select question0_.QSID as QSID2_, question0_.USERSID as USERSID2_, question0_.TITLE as TITLE2_, question0_.CONTENT as CONTENT2_, question0_.STATU as STATU2_, question0_.ANSWERNUM as ANSWERNUM2_, question0_.TIME as TIME2_, question0_.usersid as usersid2_ from WQFN.QUESTION question0_ order by question0_.ANSWERNUM desc ) where rownum <= ?
2011-10-27 08:41:52,671 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2011-10-27 08:41:52,687 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2011-10-27 08:41:52,687 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
2011-10-27 08:41:52,703 DEBUG [org.hibernate.util.JDBCExceptionReporter] - could not execute query [select question0_.QSID as QSID2_, question0_.USERSID as USERSID2_, question0_.TITLE as TITLE2_, question0_.CONTENT as CONTENT2_, question0_.STATU as STATU2_, question0_.ANSWERNUM as ANSWERNUM2_, question0_.TIME as TIME2_, question0_.usersid as usersid2_ from WQFN.QUESTION question0_ order by question0_.ANSWERNUM desc]
java.sql.SQLException: ORA-00918: 未明确定义列sql : 
select * from ( select question0_.QSID as QSID2_, question0_.USERSID as USERSID2_, question0_.TITLE as TITLE2_, question0_.CONTENT as CONTENT2_, question0_.STATU as STATU2_, question0_.ANSWERNUM as ANSWERNUM2_, question0_.TIME as TIME2_, question0_.usersid as usersid2_ from WQFN.QUESTION question0_ order by question0_.ANSWERNUM desc ) where rownum <= 2   
在数据库中都运行错误sql: 不要 前边的 select * from  和 后边的 where rownum<=2 就对了 
select question0_.QSID as QSID2_, question0_.USERSID as USERSID2_, question0_.TITLE as TITLE2_, question0_.CONTENT as CONTENT2_, question0_.STATU as STATU2_, question0_.ANSWERNUM as ANSWERNUM2_, question0_.TIME as TIME2_, question0_.usersid as usersid2_ from WQFN.QUESTION question0_ order by question0_.ANSWERNUM desc 求高手 !!!

解决方案 »

  1.   

    你参照着改hql吧。(改造“在数据库中都运行错误”的sql)
    select rownum, t.* from ( ...... )t
    where rownum <= 2
      

  2.   

    那hql在程序里怎么改啊  这是自动生成的  
    我只写了 :
    String hql="from Question q order by q.answernum desc";
    Query q=super.getSession().createQuery(hql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    return q.list();