Search code examples
hibernatehqldistinct

How do you create a Distinct query in 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".


Solution

  • 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});