【问题标题】:HQL combined "distinct" and "order by"HQL 结合了“distinct”和“order by”
【发布时间】:2012-11-14 13:49:02
【问题描述】:

如果我删除“distinct”或“order by”,则此查询有效,但组合起来无效。我正在尝试遵循示例。你能解释一下吗?

String queryString = "select distinct event.county from Event as event order by event.county.county"

[main] - [ERROR] SqlExceptionHelper.logExceptions():144 >> ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
  Position: 215

生成的 SQL

select distinct county1_.Id as Id4_, county1_.County as County4_ from Event event0_ inner join County county1_ on event0_.CountyID=county1_.Id cross join County county2_ where event0_.CountyID=county2_.Id order by county2_.County 

【问题讨论】:

    标签: hibernate jpa jpa-2.0 hql


    【解决方案1】:

    试试

    select distinct county from Event event
    inner join event.county county
    order by county.county
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多