Reputation: 15
I have a Entity Book, a DTO and a Repository for this Class.
I'm trying to query all the results into the DTO I found this: select new br.com.fall.controllers.dto.LivroDTO(l.name,l.page, l.publisher,l.cat1,l.cat2,l.cat3,l.launchDate) from Book l where l.name LIKE %?1
But, I need eliminate books with repeated name, like something: select distinct (name) new BookDTO ...
Did someone know how to do this with @Query Annotation? Or I need to filter this by code?
Upvotes: 0
Views: 32
Reputation: 6184
You can do sou by simply adding the distinct
keyword:
select distinct new br.com.fall.controllers.dto.LivroDTO(l.name,l.page, l.publisher,l.cat1,l.cat2,l.cat3,l.launchDate) from Book l where l.name LIKE %?1
This distinct will apply to all fields, you cannot apply this to name
only.
Upvotes: 1