How do you create a Distinct query in 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});

Hibernate criteria: Joining table without a mapped association

This is indeed possible with criteria: DetachedCriteria ownerCriteria = DetachedCriteria.forClass(Owner.class); ownerCriteria.setProjection(Property.forName(“id”)); ownerCriteria.add(Restrictions.eq(“ownername”, “bob”)); Criteria criteria = getSession().createCriteria(Pet.class); criteria.add(Property.forName(“ownerId”).in(ownerCriteria)); Update: This actually performs a sub-query instead of a join but it allows you to use Criteria on two entities that do not have a hibernate relationship defined.