Q:

How do I specify DISTINCT when using JPA 2?

I'm using Hibernate 4.1.0.Final, MySQL 5.5, and JPA 2.0.  When returning values from my JPA query, how do I specify a "distinct" clause without rewriting my function to be an SQL (or JPQL) statement?  Below if how I have coded my JPA method so far ...
final List<ReturnedObject> foundReturnedObjects = new ArrayList<ReturnedObject>();

final CriteriaBuilder builder = m_entityManager.getCriteriaBuilder();
final CriteriaQuery<ReturnedObject> query = builder.createQuery(ReturnedObject.class);

final Root<JoinedObject> JoinedObject = query.from(JoinedObject.class);
final Join<JoinedObject, ReturnedObject> ReturnedObject = JoinedObject.join(JoinedObject_.returnedObject);
if (params != null && !params.isEmpty()) 
{
    query.where(JoinedObject.get(JoinedObject_.organization).in(params));
    query.select(ReturnedObject);
    foundReturnedObjects.addAll(m_entityManager.createQuery(query).getResultList());
} // if
return foundReturnedObjects;

However, the problem is duplicate items could potentially be returned.  Note, I realize I could transfer all the results to a java.util.Set, but this question is specifically about executing the SQL with a DISTINCT clause instead of doing that work after the query has returned.

A:

That can be done by using distinct method, which can be found from CriteriaQuery itself:
query.distinct(true);

