Search code examples
javajpaeclipselink

How to get unique results in JPA


I am using this JPA-Query (EclipseLink):

SELECT e FROM Entity e GROUP BY e.label

But i get all rows in my result instead of only the unique labels.

My second approach was using DISTINCT like i did successfully in another function which counts the distinct values, but i don't know how apply this to get the Entities:

SELECT COUNT(DISTINCT e.label) FROM Entity e

Solution

  • From the Hibernate JP-QL documentation:

    select distinct e.label from Entity e
    

    However, it seems you want the full entities, which I don't think is possible.