开发者

How to get unique results in JPA

开发者 https://www.devze.com 2023-03-26 20:39 出处:网络
I am using this JPA-Query (EclipseLink): SELECT e FROM Entity e GROUP BY e.label But i get all rows in my result开发者_如何学C instead of only the unique labels.

I am using this JPA-Query (EclipseLink):

SELECT e FROM Entity e GROUP BY e.label

But i get all rows in my result开发者_如何学C 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


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.


actually, it is possible, for example :

    @NamedQuery(name = "WorkingDay.WorkersAtADay", query = "SELECT DISTINCT w.worker FROM WorkingDay w WHERE w.date = :Date"),
0

精彩评论

暂无评论...
验证码 换一张
取 消