这是我的查询语句:String hql="from Bid as bd where bd.bidPrice in (select max(bd.bidPrice) from Bid)";
错误提示如下:
严重: Servlet.service() for servlet action threw exception
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]聚合不应出现在 WHERE 子句中,除非该聚合位于 HAVING 子句或选择列表所包含的子查询中,并且要对其进行聚合的列是外部引用。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)

解决方案 »

  1.   

    String hql="from Bid as bd where bd.bidPrice in (select max(bd2.bidPrice) from Bid bd2)"; 
      

  2.   

    楼主你在查询分析器里执行下我感觉你的sql不能达到你的要求
      

  3.   

    <property name="show_sql">true</property>
      

  4.   

    String hql="from Bid as bd where bd.bidPrice in (select max(bidPrice) from Bid)"; 
    写SQL语句也行 。。能通过就好
      

  5.   

    直接用hibernate支持的sql或用他的子查询抓取策略不过控制台生成的语句其实都是一样的先测试下你的SQL语句能查到么