你如何在HQL中创建一个独特的查询 [英] How do you create a Distinct query in HQL

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

问题描述

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

解决方案

这是我们使用的一个hql片段。 (名称已更改为保护身份)

$ $ p $ $ $ code> String queryString =从Foo中选择不同的f f内部连接foo.bars为b +
where f.creationDate> =?and f.creationDate<?and b.bar =?;
return getHibernateTemplate()。find(queryString,new Object [] {startDate,endDate,bar});


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".

解决方案

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中创建一个独特的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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