如何在 HQL 中创建 Distinct 查询 [英] How do you create a Distinct query in HQL

查看:66
本文介绍了如何在 HQL 中创建 Distinct 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 HQL 中创建一个 Distinct 查询.通过使用distinct"关键字或其他一些方法.我不确定 distinct 是否是 HQL 的有效关键字,但我正在寻找与 SQL 关键字distinct"等效的 HQL.

Is there a way to create a Distinct query in HQL. Either by using the "distinct" keyword or some other method. I am not sure if distinct is a valid keywork for HQL, but I am looking for the HQL equivalent of the SQL keyword "distinct".

推荐答案

这是我们使用的 hql 片段.(已更改名称以保护身份)

Here's a snippet of hql that we use. (Names have been changed to protect identities)

String queryString = "select distinct f from Foo f inner join foo.bars as b" +
                " where f.creationDate >= ? and f.creationDate < ? and b.bar = ?";
        return getHibernateTemplate().find(queryString, new Object[] {startDate, endDate, bar});

这篇关于如何在 HQL 中创建 Distinct 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆