当前位置: 代码迷 >> Java Web开发 >> hql 用了order by+rownum ORA-00918: 未明确定义列 指教!
  详细解决方案

hql 用了order by+rownum ORA-00918: 未明确定义列 指教!

热度:1018   发布时间:2016-04-17 00:26:21.0
hql 用了order by+rownum ORA-00918: 未明确定义列 在线等指教!!!
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 

求高手 !!!

------解决方案--------------------
你参照着改hql吧。

(改造“在数据库中都运行错误”的sql)
select rownum, t.* from ( ...... )t
where rownum <= 2
  相关解决方案