Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用distinct和order by进行hibernate sql查询_Sql_Hibernate - Fatal编程技术网

使用distinct和order by进行hibernate sql查询

使用distinct和order by进行hibernate sql查询,sql,hibernate,Sql,Hibernate,我有一个疑问: "select distinct d from Dance d " + "inner join d.meisterschaftDances ms " + "inner join ms.danceRegistrations dr " + "inner join dr.user u " + "where (u.id = :userId " + &

我有一个疑问:

"select distinct d from Dance d " +
    "inner join d.meisterschaftDances ms " +
    "inner join ms.danceRegistrations dr " +
    "inner join dr.user u " +
    "where (u.id = :userId " +
    "or d.user.id = :userId) " +
    "AND ms.meisterschaft.open = FALSE " +
    "order by ms.meisterschaft.organizer.id, " +
    "d.discipline, d.age, d.category, " +
    "d.class"
逻辑对我来说是完美的,但正如我们所知,
distinct
对于
orderby
来说并不容易

我多次跳同一支舞,因为迈斯特舞曲的内部连接可以有几个参考


可悲的是,我不知道如何重写我的查询,使其工作正常。有人能给我举个例子吗。正如hibernate中所述,谢谢您:

对于JPQL和HQL,DISTINCT有两种含义:

  • 它可以传递到数据库,以便从结果集中删除重复项

  • 在联接获取子集合时,它可用于筛选出相同的父实体引用

  • 您对第二种情况感兴趣,因此需要添加
    QueryHints.HINT\u PASS\u DISTINCT\u THROUGH
    HINT,如下所示:

    List=entityManager.createQuery(
    “选择不同的d”+
    “来自舞蹈d”+
    “内接d.Meisterschaftms…”,舞蹈课)
    .setHint(QueryHints.HINT\u PASS\u DISTINCT\u THROUGH,false)
    .getResultList();
    

    另外,由于存在bug,上述方法在某些hibernate版本中可能不可行(请参见示例和)

    我目前正在将quarkus与hibernate 5.5.0一起使用,因此希望在此hibernate版本中已经修复了任何问题。非常感谢