title: Using DISTINCT keyword in JPA on individual columns
body: <p>I am reading some values from a database that is horribly un-normalized (which I can't control).  The call retrieves announcements for university departments, and if a user is in multiple departments (which is possible), then the same results are returned multiple times for these users.  However, some departments might have different announcements, while some have the same.  </p>
  
  <p>Is there a way for me to use the DISTINCT keyword in JPA on individual columns?  This is what I currently have for the query:</p>
  
  <pre><code>String jpql = "SELECT DISTINCT annoucement FROM Announcment announcement "
                  + "WHERE (announcement.date &lt;= :now AND announcement.endDate &gt;= :now) "
                  + "AND announcement.approved = true AND announcement.departmentId IN (:departmentIDs)";
  
  TypedQuery&lt;Announcement&gt; query = entityManager.createQuery(jpql,
                  Announcement.class);
  query.setParameter("now", new Date());
  query.setParameter("departmentIDs", departmentIDs);
  </code></pre>
  
  <p>The departmentID value might be different, but the announcement, dates, etc. are all identical.  This query returns announcements that have duplicate values. </p>